Issue connecting SmtpClient
-
I had found a very useful SMTP Client repository on GitHub (https://github.com/bluetiger9/SmtpClient-for-Qt). I am using this to send emails via an interface in Qt. I seem to be missing a DLL by my error messages, or not connecting a library somewhere. The error messages I am getting are as followed:
C:\Users\Admin\Documents\EmailTest\mainwindow.cpp:27: error: undefined reference to `_imp___ZN11MimeMessageC1Eb' debug/mainwindow.o: In function `ZN10MainWindow4testEv': C:\Users\Admin\Documents\EmailTest/mainwindow.cpp:27: undefined reference to `_imp___ZN11MimeMessageC1Eb'
There are many more like that, 25 total. I attached my .pro file below
QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport CONFIG += c++17 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ emailaddress.cpp \ main.cpp \ mainwindow.cpp \ mimeattachment.cpp \ mimebase64encoder.cpp \ mimebase64formatter.cpp \ mimebytearrayattachment.cpp \ mimecontentencoder.cpp \ mimecontentformatter.cpp \ mimefile.cpp \ mimehtml.cpp \ mimeinlinefile.cpp \ mimemessage.cpp \ mimemultipart.cpp \ mimepart.cpp \ mimeqpencoder.cpp \ mimeqpformatter.cpp \ mimetext.cpp \ quotedprintable.cpp \ smtpclient.cpp HEADERS += \ emailaddress.h \ mainwindow.h \ mimeattachment.h \ mimebase64encoder.h \ mimebase64formatter.h \ mimebytearrayattachment.h \ mimecontentencoder.h \ mimecontentformatter.h \ mimefile.h \ mimehtml.h \ mimeinlinefile.h \ mimemessage.h \ mimemultipart.h \ mimepart.h \ mimeqpencoder.h \ mimeqpformatter.h \ mimetext.h \ quotedprintable.h \ smtpclient.h \ smtpmime_global.h FORMS += \ mainwindow.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
Within my mainwindow.cpp, I have the code for demos\demo1\demo1.cpp.
mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include "smtpclient.h" #include "mimepart.h" #include "mimehtml.h" #include "mimeattachment.h" #include "mimemessage.h" #include "mimetext.h" #include "mimeinlinefile.h" #include "mimefile.h" #include "mimebytearrayattachment.h" MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); test(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::test() { // This is a first demo application of the SmtpClient for Qt project // Now we create a MimeMessage object. This is the email. MimeMessage message; EmailAddress sender("email@gmail.com", "my name"); message.setSender(sender); EmailAddress to("recepient@yahoo.com", "their name"); message.addRecipient(to); message.setSubject("SmtpClient for Qt - Demo"); // Now add some text to the email. // First we create a MimeText object. MimeText text; text.setText("Hi,\nThis is a simple email message.\n"); // Now add it to the mail message.addPart(&text); // Now we can send the mail SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); smtp.connectToHost(); if (!smtp.waitForReadyConnected()) { qDebug() << "Failed to connect to host!"; } smtp.login("email@gmail.com", "password"); if (!smtp.waitForAuthenticated()) { qDebug() << "Failed to login!"; } smtp.sendMail(message); if (!smtp.waitForMailSent()) { qDebug() << "Failed to send mail!"; } smtp.quit(); }
Hopefully, someone has used this repository before and can lead me in the right direction. I have already downloaded OpenSSL through the Qt Maintenance Tool, and set that within the Build Path.
Thanks in advance!
-
@orsini29 said in Issue connecting SmtpClient:
and just reference the *.pro file within my EmailTest.pro file, by using the LIBS keyword, correct?
No, you do not reference any pro files via LIBS. You reference libraries. Please read https://doc.qt.io/qt-6/qmake-variable-reference.html#libs
-
The project being a library, it contains the usual import/export macros that are required when building shared libraries on Windows. I am wondering whether the way you include the code makes this problematic.
-
Interesting..I am a little confused on what would be the correct way to include the code then, is there a more uniform way to include it rather than the way I did? I just copied the *.cpp and *.h files into the project folder, then added them via Qt Creator to the project tree. I assume this is the wrong way, being there are issues arising.
How would you suggest to go about this? Thanks in advance!
-
@SGaist
Confused on what you mean by that, I am attempting to integrate this into a pre-existing project to send emails when certain issues arise, to warn someone who is not using the software of an issue on the computer...are you saying to clone the repository, and then move my project into the cloned repository? -
@SGaist
I hate to be annoying, but I am just still confused. How would you go about using this in the correct way then? I'm sure it's super simple, and I'll kick myself once you help me but I just do not see it right now..Not looking for an answer but I guess just more of a push in the right direction..sorry again for making a simple problem more difficult then it needs to be -
Open SMTPEmail.pro with Qt Creator, build it for debug and release. Install it somewhere central and then use LIBS to setup its use with your project.
-
@orsini29 said in Issue connecting SmtpClient:
and just reference the *.pro file within my EmailTest.pro file, by using the LIBS keyword, correct?
No, you do not reference any pro files via LIBS. You reference libraries. Please read https://doc.qt.io/qt-6/qmake-variable-reference.html#libs
-
-
Thanks for your assistance, got it all figured out. Sorry for the elementary questions, but thanks again!!
For anyone in the future, @jsulm had a useful link to point me in the correct direction with referencing the library, along with @SGaist explaining about compiling the project, rather then just using the source files.
-
Hello, @orsini29 I am encountering the same issue and I am lost as well. I have read everything that has been suggested but I am still not sure how to concretely implement stmp into my project. Could you be more specific on how you have manage to do it please ? It would be a great help to me, thanks :)