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. SMTP works fine when running on Qt, issue when application is packaged
Forum Updated to NodeBB v4.3 + New Features

SMTP works fine when running on Qt, issue when application is packaged

Scheduled Pinned Locked Moved Solved 3rd Party Software
28 Posts 3 Posters 6.3k Views 2 Watching
  • 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.
  • JonBJ JonB

    @maverick13
    OK, I think you are at a sensible place now, if I understand right.

    The bad case now fails to connect but at least times out?

    Since it works in Creator and you need to test the "deployed" build you can't use a debugger. If it were me I would go through whatever code this is that you are using and put whatever "debug" statements in until I identified exactly where the connection is failing to be made. That might be qDebug() statements if you can show them under Windows or printf()s or message boxes or log to file.

    My hunch is that the deployed one is not using quite the same libraries as the development one? For example, the smtp connection is across SSL, where does that come from? Or some other difference in environment. But it could even be a bug that is in code and just happens to only show up in the installed case. You just don't know.

    M Offline
    M Offline
    maverick13
    wrote on last edited by maverick13
    #17

    @JonB

    Awesome. Thanks for the help, I appreciate it. I won't close the thread, just becuase if I have any questions, you are definitely more versed to answer and speak on things I do not quite grasp or see at first glance. Really appreciate helping to this point. I'm going to do a bit more debugging and see if I get anywhere.

    The worst part of software engineering is the debugging...the best part is figuring out the bug and seeing it work :D

    edit: also, if I do reply to you via this thread, if I ever think I have a mini breakthrough -- do you get notified or is it ok to send you a PM?

    JonBJ 1 Reply Last reply
    0
    • M maverick13

      @JonB

      Awesome. Thanks for the help, I appreciate it. I won't close the thread, just becuase if I have any questions, you are definitely more versed to answer and speak on things I do not quite grasp or see at first glance. Really appreciate helping to this point. I'm going to do a bit more debugging and see if I get anywhere.

      The worst part of software engineering is the debugging...the best part is figuring out the bug and seeing it work :D

      edit: also, if I do reply to you via this thread, if I ever think I have a mini breakthrough -- do you get notified or is it ok to send you a PM?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #18

      @maverick13
      Just post in thread. We get notified if you reply, but we look at them anyway.

      M 1 Reply Last reply
      1
      • JonBJ JonB

        @maverick13
        Just post in thread. We get notified if you reply, but we look at them anyway.

        M Offline
        M Offline
        maverick13
        wrote on last edited by maverick13
        #19

        @JonB

        For example, the smtp connection is across SSL, where does that come from? Or some other difference in environment.

        Also, in regards to this I believe it is coming from QSslSocket, unless I am misunderstanding. I see in another method within smtpclient.cpp, this

        void SmtpClient::setConnectionType(ConnectionType ct)
        {
            this->connectionType = ct;
        
            switch (connectionType)
            {
            case TcpConnection:
                socket = new QTcpSocket(this);
                break;
            case SslConnection:
            case TlsConnection:
                socket = new QSslSocket(this);
                connect(socket, SIGNAL(encrypted()),
                        this, SLOT(socketEncrypted()));
                break;
            }
        }
        

        (I originally wanted to use TLS over SSL [I believe it is more safe with research i've done?], but now that I can't get either working, might as well forget about being picky now)

        which leads me to believe it uses a Qt library for the SSL connection. Although, I see there is no SSL connection code being ran in this..Which is odd, then doing a slight scroll down and looking at the changeState(SmtpClient::ClientState) method I see code being ran in the case for SslConnection enum. (this code will be linked below, if you want to look at the .cpp instead)

        void SmtpClient::changeState(SmtpClient::ClientState state) {
            this->state = state;
        
        #ifdef QT_NO_DEBUG
            // Emit stateChanged signal only for non-internal states
            if (state <= DisconnectingState) {
                emit stateChanged(state);
            }
        #else
            // emit all in debug mode
            qDebug() << "[SmtpClient] State:" << staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("ClientState")).valueToKey(state);
        //    std::string output(staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("ClientState")).valueToKey(state));
        //    log.writeToLogFile("[SmtpClient] State: " + output, "Error");
            emit stateChanged(state);
        #endif
        
            switch (state)
            {
            case ConnectingState:
                switch (connectionType)
                {
                case TlsConnection:
                case TcpConnection:
                    socket->connectToHost(host, port);
                    break;
                case SslConnection:
                    ((QSslSocket*) socket)->connectToHostEncrypted(host, port);
                    break;
                }
                break;
        

        Note: some of the comments were mine, I was trying to get a debugger to work this morning for the installed version. They will not show up within the repo, obviously.

        setConnectionType - https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/src/smtpclient.cpp#L228

        changeState - https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/src/smtpclient.cpp#L246

        JonBJ 1 Reply Last reply
        0
        • M maverick13

          @JonB

          For example, the smtp connection is across SSL, where does that come from? Or some other difference in environment.

          Also, in regards to this I believe it is coming from QSslSocket, unless I am misunderstanding. I see in another method within smtpclient.cpp, this

          void SmtpClient::setConnectionType(ConnectionType ct)
          {
              this->connectionType = ct;
          
              switch (connectionType)
              {
              case TcpConnection:
                  socket = new QTcpSocket(this);
                  break;
              case SslConnection:
              case TlsConnection:
                  socket = new QSslSocket(this);
                  connect(socket, SIGNAL(encrypted()),
                          this, SLOT(socketEncrypted()));
                  break;
              }
          }
          

          (I originally wanted to use TLS over SSL [I believe it is more safe with research i've done?], but now that I can't get either working, might as well forget about being picky now)

          which leads me to believe it uses a Qt library for the SSL connection. Although, I see there is no SSL connection code being ran in this..Which is odd, then doing a slight scroll down and looking at the changeState(SmtpClient::ClientState) method I see code being ran in the case for SslConnection enum. (this code will be linked below, if you want to look at the .cpp instead)

          void SmtpClient::changeState(SmtpClient::ClientState state) {
              this->state = state;
          
          #ifdef QT_NO_DEBUG
              // Emit stateChanged signal only for non-internal states
              if (state <= DisconnectingState) {
                  emit stateChanged(state);
              }
          #else
              // emit all in debug mode
              qDebug() << "[SmtpClient] State:" << staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("ClientState")).valueToKey(state);
          //    std::string output(staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("ClientState")).valueToKey(state));
          //    log.writeToLogFile("[SmtpClient] State: " + output, "Error");
              emit stateChanged(state);
          #endif
          
              switch (state)
              {
              case ConnectingState:
                  switch (connectionType)
                  {
                  case TlsConnection:
                  case TcpConnection:
                      socket->connectToHost(host, port);
                      break;
                  case SslConnection:
                      ((QSslSocket*) socket)->connectToHostEncrypted(host, port);
                      break;
                  }
                  break;
          

          Note: some of the comments were mine, I was trying to get a debugger to work this morning for the installed version. They will not show up within the repo, obviously.

          setConnectionType - https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/src/smtpclient.cpp#L228

          changeState - https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/src/smtpclient.cpp#L246

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #20

          @maverick13 said in SMTP works fine when running on Qt, issue when application is packaged:

          which leads me to believe it uses a Qt library for the SSL connection.

          Under Linux it uses OpenSSL libraries for this, and there can be issues if it picks up different versions. I don't know how this works under Windows.

          Not sure what your "Although, I see there is no SSL connection code being ran in this" means. The port number is for SSL. Do make 100% sure the two instances are trying to connect on the same port number.

          Not my area, but you might also use a tool like Wireshark to see whether/what communications are actually happening with the server.

          M 1 Reply Last reply
          1
          • JonBJ JonB

            @maverick13 said in SMTP works fine when running on Qt, issue when application is packaged:

            which leads me to believe it uses a Qt library for the SSL connection.

            Under Linux it uses OpenSSL libraries for this, and there can be issues if it picks up different versions. I don't know how this works under Windows.

            Not sure what your "Although, I see there is no SSL connection code being ran in this" means. The port number is for SSL. Do make 100% sure the two instances are trying to connect on the same port number.

            Not my area, but you might also use a tool like Wireshark to see whether/what communications are actually happening with the server.

            M Offline
            M Offline
            maverick13
            wrote on last edited by maverick13
            #21

            @JonB

            Not sure what your "Although, I see there is no SSL connection code being ran in this" means.

            Nevermind you can disregard that... I did not notice there wasn't a break statement after the 2nd case, so if it is SslConnection it will just fall through, sorry about that.

            The port number is for SSL. Do make 100% sure the two instances are trying to connect on the same port number.

            Yeah, I looked to verify that the port number is not being set anywhere within the code explicitly, which it is not. I'll go and get to debugging, thanks again.

            I've used wireshark a bit in school. Might try to get it downloaded again and see if I can pick anything up. Thanks.

            Under Linux it uses OpenSSL libraries for this, and there can be issues if it picks up different versions. I don't know how this works under Windows.

            Also, I believe it uses OpenSSL for Windows as well. I had to download OpenSSL, as well as define OpenSSL within the build environment path for Qt Creator to get it to work "properly"

            JonBJ 1 Reply Last reply
            0
            • M maverick13

              @JonB

              Not sure what your "Although, I see there is no SSL connection code being ran in this" means.

              Nevermind you can disregard that... I did not notice there wasn't a break statement after the 2nd case, so if it is SslConnection it will just fall through, sorry about that.

              The port number is for SSL. Do make 100% sure the two instances are trying to connect on the same port number.

              Yeah, I looked to verify that the port number is not being set anywhere within the code explicitly, which it is not. I'll go and get to debugging, thanks again.

              I've used wireshark a bit in school. Might try to get it downloaded again and see if I can pick anything up. Thanks.

              Under Linux it uses OpenSSL libraries for this, and there can be issues if it picks up different versions. I don't know how this works under Windows.

              Also, I believe it uses OpenSSL for Windows as well. I had to download OpenSSL, as well as define OpenSSL within the build environment path for Qt Creator to get it to work "properly"

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #22

              @maverick13
              Literally, just put some debug/trace statements into code to see just where it gets to. Then run it from Creator and from installed. Compare where installed gets to before connection failure. Print out port number etc.

              piervalliP M 2 Replies Last reply
              1
              • JonBJ JonB

                @maverick13
                Literally, just put some debug/trace statements into code to see just where it gets to. Then run it from Creator and from installed. Compare where installed gets to before connection failure. Print out port number etc.

                piervalliP Offline
                piervalliP Offline
                piervalli
                wrote on last edited by piervalli
                #23
                This post is deleted!
                1 Reply Last reply
                0
                • JonBJ JonB

                  @maverick13
                  Literally, just put some debug/trace statements into code to see just where it gets to. Then run it from Creator and from installed. Compare where installed gets to before connection failure. Print out port number etc.

                  M Offline
                  M Offline
                  maverick13
                  wrote on last edited by maverick13
                  #24

                  @JonB
                  One thing I wanted to look at was this,

                  My hunch is that the deployed one is not using quite the same libraries as the development one? For example, the smtp connection is across SSL, where does that come from? Or some other difference in environment.

                  Because I believe this is most likely the issue as well, and I might have noticed something I can't believe I didn't before. The DLL's for OpenSSL (libcrypto-1_1.dll & libssl-1_1.dll) were not in the data directory of the installer...obviously this caused an issue. I tried the following steps:

                  • Cleared out the DLL's from the data directory

                  • Placed myself within the C:\Qt\5.15.12\mingw81_32\bin\ directory within PowerShell

                  • Ran the following command .\windeployqt.exe '..\..\..\..\Users\Admin\Documents\Qt Installers\TestInstaller\packages\com.email.test\data\TestingSMTP.exe', where TestingSMTP.exe is the executable created from running via Qt Creator. I ran this prior to this experiment, but wanted to run it again to cover all my bases.

                  • I noticed that the OpenSSL DLLs were not being copied to the data directory...so I manually copied them in from the directory that I initialized within the Projects -> Build Environment -> Path (pictured below)

                  9489ecf8-754d-470b-999c-0b521cad64ae-image.png

                  It works now, although I did switch which GitHub repository I was using, as I had found the original one we were debugging with after using a different one without MIME capabilities (I believe MIME is sending to multiple users? Might be the wrong word, but that's the capability the one I have working now was missing).

                  So, I am going to try this on the original one, which is the one I need to get working, but at least there is something.

                  Any idea why the OpenSSL DLLs did not copy over with the windeployqt command? Or does this command purposefully not copy these DLLs over?

                  Edit: Just tested it with the original repository, worked fine. Now just need to implement it within my actual project and not the demo, and hopefully all goes smoothly. Still curious about this though, if anyone knows.

                  Any idea why the OpenSSL DLLs did not copy over with the windeployqt command? Or does this command purposefully not copy these DLLs over?

                  JonBJ 1 Reply Last reply
                  0
                  • M maverick13 has marked this topic as solved on
                  • M maverick13

                    @JonB
                    One thing I wanted to look at was this,

                    My hunch is that the deployed one is not using quite the same libraries as the development one? For example, the smtp connection is across SSL, where does that come from? Or some other difference in environment.

                    Because I believe this is most likely the issue as well, and I might have noticed something I can't believe I didn't before. The DLL's for OpenSSL (libcrypto-1_1.dll & libssl-1_1.dll) were not in the data directory of the installer...obviously this caused an issue. I tried the following steps:

                    • Cleared out the DLL's from the data directory

                    • Placed myself within the C:\Qt\5.15.12\mingw81_32\bin\ directory within PowerShell

                    • Ran the following command .\windeployqt.exe '..\..\..\..\Users\Admin\Documents\Qt Installers\TestInstaller\packages\com.email.test\data\TestingSMTP.exe', where TestingSMTP.exe is the executable created from running via Qt Creator. I ran this prior to this experiment, but wanted to run it again to cover all my bases.

                    • I noticed that the OpenSSL DLLs were not being copied to the data directory...so I manually copied them in from the directory that I initialized within the Projects -> Build Environment -> Path (pictured below)

                    9489ecf8-754d-470b-999c-0b521cad64ae-image.png

                    It works now, although I did switch which GitHub repository I was using, as I had found the original one we were debugging with after using a different one without MIME capabilities (I believe MIME is sending to multiple users? Might be the wrong word, but that's the capability the one I have working now was missing).

                    So, I am going to try this on the original one, which is the one I need to get working, but at least there is something.

                    Any idea why the OpenSSL DLLs did not copy over with the windeployqt command? Or does this command purposefully not copy these DLLs over?

                    Edit: Just tested it with the original repository, worked fine. Now just need to implement it within my actual project and not the demo, and hopefully all goes smoothly. Still curious about this though, if anyone knows.

                    Any idea why the OpenSSL DLLs did not copy over with the windeployqt command? Or does this command purposefully not copy these DLLs over?

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #25

                    @maverick13

                    So are you saying that now, with the locally-copied SSL DLLs, your packaged/deployed/installed SMTP client application finally works, as it did from Creator with the development directory? I think you are, because you have marked the topic as solved.

                    The perhaps it was picking up the SSL DLLs from elsewhere on your machine? Or not finding them at all, but not warning? Since the port is for SSL one might guess that a problem/incompatibility there could cause malfunction, though shame there was no apparent indication/feedback for this.

                    @maverick13 said in SMTP works fine when running on Qt, issue when application is packaged:

                    Any idea why the OpenSSL DLLs did not copy over with the windeployqt command? Or does this command purposefully not copy these DLLs over?

                    You will have to await someone else for this. I have never used linuxdeployqt. Maybe it expects SSL DLLs to be system-wide resources so not to copy/install locally?

                    M 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @maverick13

                      So are you saying that now, with the locally-copied SSL DLLs, your packaged/deployed/installed SMTP client application finally works, as it did from Creator with the development directory? I think you are, because you have marked the topic as solved.

                      The perhaps it was picking up the SSL DLLs from elsewhere on your machine? Or not finding them at all, but not warning? Since the port is for SSL one might guess that a problem/incompatibility there could cause malfunction, though shame there was no apparent indication/feedback for this.

                      @maverick13 said in SMTP works fine when running on Qt, issue when application is packaged:

                      Any idea why the OpenSSL DLLs did not copy over with the windeployqt command? Or does this command purposefully not copy these DLLs over?

                      You will have to await someone else for this. I have never used linuxdeployqt. Maybe it expects SSL DLLs to be system-wide resources so not to copy/install locally?

                      M Offline
                      M Offline
                      maverick13
                      wrote on last edited by maverick13
                      #26

                      Yes, it ended up working fine on my actual project, as it did with the demo project I was using as a tester, within this thread. Thanks for your help @JonB, hopefully I can get some feedback for someone on the question below, but regardless, you've been very helpful in the debugging process!

                      Any idea why the OpenSSL DLLs did not copy over with the windeployqt command? Or does this command purposefully not copy these DLLs over?

                      Also, one more small question. I should be using TLS over SSL, correct? I believe from my prior research, TLS is more secure with encryption, and less prone to getting the email swiped/edited within transit, or did I misinterpret? While I am never sending sensitive data with this, I still like to look at the security side of things, always just to be safe.

                      piervalliP 1 Reply Last reply
                      0
                      • M maverick13

                        Yes, it ended up working fine on my actual project, as it did with the demo project I was using as a tester, within this thread. Thanks for your help @JonB, hopefully I can get some feedback for someone on the question below, but regardless, you've been very helpful in the debugging process!

                        Any idea why the OpenSSL DLLs did not copy over with the windeployqt command? Or does this command purposefully not copy these DLLs over?

                        Also, one more small question. I should be using TLS over SSL, correct? I believe from my prior research, TLS is more secure with encryption, and less prone to getting the email swiped/edited within transit, or did I misinterpret? While I am never sending sensitive data with this, I still like to look at the security side of things, always just to be safe.

                        piervalliP Offline
                        piervalliP Offline
                        piervalli
                        wrote on last edited by
                        #27

                        @maverick13
                        The standard going to TLS, for instance Microsoft on Azure the minimum standard Is TLS 1.1

                        M 1 Reply Last reply
                        1
                        • piervalliP piervalli

                          @maverick13
                          The standard going to TLS, for instance Microsoft on Azure the minimum standard Is TLS 1.1

                          M Offline
                          M Offline
                          maverick13
                          wrote on last edited by
                          #28

                          @piervalli

                          Awesome, thank you! I will move ahead with TLS as I expected. Thanks for your assistance earlier as well!

                          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