Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Issue connecting SmtpClient

Issue connecting SmtpClient

Scheduled Pinned Locked Moved Solved 3rd Party Software
17 Posts 5 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    orsini29
    wrote on 17 Apr 2023, 16:11 last edited by orsini29
    #1

    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

    EmailTest.pro

    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!

    S 1 Reply Last reply 17 Apr 2023, 18:24
    1
    • O orsini29
      17 Apr 2023, 20:18

      @SGaist
      Along with the *.cpp and *.h files correct? Basically have that project set aside somewhere local, and just reference the *.pro file within my EmailTest.pro file, by using the LIBS keyword, correct?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 Apr 2023, 05:35 last edited by
      #14

      @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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 1 Reply Last reply 19 Apr 2023, 12:43
      1
      • O orsini29
        17 Apr 2023, 16:11

        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

        EmailTest.pro

        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!

        S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 17 Apr 2023, 18:24 last edited by
        #2

        Hi,

        Did you copy the code of that library inside your project ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        O 1 Reply Last reply 17 Apr 2023, 19:03
        1
        • S SGaist
          17 Apr 2023, 18:24

          Hi,

          Did you copy the code of that library inside your project ?

          O Offline
          O Offline
          orsini29
          wrote on 17 Apr 2023, 19:03 last edited by
          #3

          @SGaist
          Yes, I have all the *.cpp and *.h files in the project tree, along with being instantiated in the *.pro file.

          90037d06-fd28-47ef-9d5a-c6802017d4b9-image.png

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 17 Apr 2023, 19:16 last edited by
            #4

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            O 1 Reply Last reply 17 Apr 2023, 19:23
            1
            • S SGaist
              17 Apr 2023, 19:16

              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.

              O Offline
              O Offline
              orsini29
              wrote on 17 Apr 2023, 19:23 last edited by
              #5

              @SGaist

              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!

              S 1 Reply Last reply 17 Apr 2023, 19:31
              0
              • O orsini29
                17 Apr 2023, 19:23

                @SGaist

                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!

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 17 Apr 2023, 19:31 last edited by
                #6

                Why not build the project and use it as a library as it is meant ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                O 1 Reply Last reply 17 Apr 2023, 19:47
                1
                • S SGaist
                  17 Apr 2023, 19:31

                  Why not build the project and use it as a library as it is meant ?

                  O Offline
                  O Offline
                  orsini29
                  wrote on 17 Apr 2023, 19:47 last edited by
                  #7

                  @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?

                  S 1 Reply Last reply 17 Apr 2023, 19:48
                  0
                  • O orsini29
                    17 Apr 2023, 19:47

                    @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?

                    S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 17 Apr 2023, 19:48 last edited by
                    #8

                    No, clone the repository, build the project and then use it as you would any other C++ library.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    O 1 Reply Last reply 17 Apr 2023, 19:57
                    1
                    • S SGaist
                      17 Apr 2023, 19:48

                      No, clone the repository, build the project and then use it as you would any other C++ library.

                      O Offline
                      O Offline
                      orsini29
                      wrote on 17 Apr 2023, 19:57 last edited by
                      #9

                      @SGaist
                      Is that not what I am doing in this sense? I assume there a knowledge gap on my end, not using it as a library correctly..

                      S 1 Reply Last reply 17 Apr 2023, 19:59
                      0
                      • O orsini29
                        17 Apr 2023, 19:57

                        @SGaist
                        Is that not what I am doing in this sense? I assume there a knowledge gap on my end, not using it as a library correctly..

                        S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 17 Apr 2023, 19:59 last edited by
                        #10

                        What you did is copy the files over to your project.

                        That's not how you use a library.

                        As an example, you are not copying the Qt files in your project to use it.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        O 1 Reply Last reply 17 Apr 2023, 20:07
                        1
                        • S SGaist
                          17 Apr 2023, 19:59

                          What you did is copy the files over to your project.

                          That's not how you use a library.

                          As an example, you are not copying the Qt files in your project to use it.

                          O Offline
                          O Offline
                          orsini29
                          wrote on 17 Apr 2023, 20:07 last edited by
                          #11

                          @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

                          S 1 Reply Last reply 17 Apr 2023, 20:11
                          0
                          • O orsini29
                            17 Apr 2023, 20:07

                            @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

                            S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 17 Apr 2023, 20:11 last edited by
                            #12

                            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.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            O 1 Reply Last reply 17 Apr 2023, 20:18
                            1
                            • S SGaist
                              17 Apr 2023, 20:11

                              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.

                              O Offline
                              O Offline
                              orsini29
                              wrote on 17 Apr 2023, 20:18 last edited by
                              #13

                              @SGaist
                              Along with the *.cpp and *.h files correct? Basically have that project set aside somewhere local, and just reference the *.pro file within my EmailTest.pro file, by using the LIBS keyword, correct?

                              J 1 Reply Last reply 18 Apr 2023, 05:35
                              0
                              • O orsini29
                                17 Apr 2023, 20:18

                                @SGaist
                                Along with the *.cpp and *.h files correct? Basically have that project set aside somewhere local, and just reference the *.pro file within my EmailTest.pro file, by using the LIBS keyword, correct?

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 18 Apr 2023, 05:35 last edited by
                                #14

                                @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

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                O 1 Reply Last reply 19 Apr 2023, 12:43
                                1
                                • O orsini29 has marked this topic as solved on 19 Apr 2023, 12:38
                                • J jsulm
                                  18 Apr 2023, 05:35

                                  @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

                                  O Offline
                                  O Offline
                                  orsini29
                                  wrote on 19 Apr 2023, 12:43 last edited by
                                  #15

                                  @jsulm @SGaist

                                  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.

                                  1 Reply Last reply
                                  0
                                  • U Offline
                                    U Offline
                                    UserNotFound
                                    wrote on 6 May 2024, 12:08 last edited by
                                    #16

                                    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 :)

                                    M 1 Reply Last reply 10 Mar 2025, 17:56
                                    0
                                    • U UserNotFound
                                      6 May 2024, 12:08

                                      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 :)

                                      M Offline
                                      M Offline
                                      mr.paco
                                      wrote on 10 Mar 2025, 17:56 last edited by
                                      #17

                                      @UserNotFound just remove second Q_DECL_IMPORT from smtpmime_global.h :

                                      #ifndef SMTPMIME_GLOBAL_H
                                      #define SMTPMIME_GLOBAL_H

                                      #ifdef SMTP_MIME_LIBRARY
                                      #define SMTP_MIME_EXPORT Q_DECL_EXPORT
                                      #else
                                      #define SMTP_MIME_EXPORT
                                      #endif

                                      #endif // SMTPMIME_GLOBAL_H

                                      1 Reply Last reply
                                      0

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved