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.
  • M maverick13

    I am currently trying to make an application using the following GitHub repo (https://github.com/bluetiger9/SmtpClient-for-Qt) to send emails. I am working with one of the demo's, and on my environment when running through Qt it works fine. (working with demo2, https://github.com/bluetiger9/SmtpClient-for-Qt/tree/v2.0/demos/demo2)

    Though, when I package the application and then download it and attempt to send the email, the program crashes..I tried to create a logging capability to log everything that is being printed out with qDebug() to a file being I cannot see the console when running through the downloaded application, but all I receive is this in the file

    5/4/2023 | 15:59:2 | Admin: Socket] State:
    5/4/2023 | 15:59:2 | Admin: ocket] State:
    
    

    I set up my *.pro file as followed,

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    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 += \
        main.cpp \
        sendemail.cpp
    
    HEADERS += \
        sendemail.h
    
    FORMS += \
        sendemail.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    LIBS += \
        SmtpMime2.dll
    
    

    Everything in the *.cpp and *.h files are the same as the demo. As well, I am using the same parameters for the port/domain/sender/sender pass as I was when running through Qt when it worked.

    • Port 465, smtp.gmail.com, my gmail email, and my gmail password.

    Attached below is the folder for my project directory. I put all the source files within the GitHub repo in a source folder, just because I was trying everything to see if it would change anything but it did not. I had the DLL that was created from running the original GitHub project in the folder path (SmtpMime2.dll), along with the libSmtpMime2.a file, although I am unsure if my issue could be I am not referencing this anywhere in the *.pro?

    d9a23a32-f401-4ae3-b690-ace4e8b9b5a3-image.png

    As well, I placed the SmtpMime2.dll file in the TestInstaller/packages/com.emailtest.test/data/ folder path, where The TestInstaller holds the installer, which is where I am seeing the issue with it not working.

    Sorry, I know that was a lot and if I need to be more concise let me know. Thanks in advance, hoping someone can spot something I haven't.

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

    @maverick13
    I use the some project, try to rebuild the dll in local space.

    Pier

    M 1 Reply Last reply
    1
    • piervalliP piervalli

      @maverick13
      I use the some project, try to rebuild the dll in local space.

      Pier

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

      @piervalli

      Thanks for the advice, although I am not sure what you mean by/how to install the dll in a local space? Would I have to use the INSTALLS keyword within the *.pro file of the project itself when creating the DLL? Thanks so much!

      piervalliP 1 Reply Last reply
      0
      • M maverick13

        @piervalli

        Thanks for the advice, although I am not sure what you mean by/how to install the dll in a local space? Would I have to use the INSTALLS keyword within the *.pro file of the project itself when creating the DLL? Thanks so much!

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

        @maverick13

        1. git clone https://github.com/bluetiger9/SmtpClient-for-Qt.git
        2. open the project with Qt creator the file src/SMTPEmail.pro
        3. build it creates the dll.
        1 Reply Last reply
        1
        • M Offline
          M Offline
          maverick13
          wrote on last edited by
          #5

          @piervalli

          Thanks, I originally did that, but I think I might have messed up the following step, and I do not remember exactly what I did, so this could be the issue.

          When I go to build the project, I receive the following error

          You need to set an executable in the custom run configuration.
          

          I assume this means I need to go into here:

          9a233b4f-279f-48bd-a40c-f25afe6fc9a3-image.png

          Where it says 'Executable', and define something, although I am unsure what this would be.

          As well, even with this error I see the SmtpMime2.dll is still created, and then when I package the application and go to run the executable the message still does not send...Not sure if there's anything else you see, but it seems very odd this isn't working. Has to be something I am doing wrong.

          piervalliP 1 Reply Last reply
          0
          • M maverick13

            @piervalli

            Thanks, I originally did that, but I think I might have messed up the following step, and I do not remember exactly what I did, so this could be the issue.

            When I go to build the project, I receive the following error

            You need to set an executable in the custom run configuration.
            

            I assume this means I need to go into here:

            9a233b4f-279f-48bd-a40c-f25afe6fc9a3-image.png

            Where it says 'Executable', and define something, although I am unsure what this would be.

            As well, even with this error I see the SmtpMime2.dll is still created, and then when I package the application and go to run the executable the message still does not send...Not sure if there's anything else you see, but it seems very odd this isn't working. Has to be something I am doing wrong.

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

            @maverick13

            Build only not run, because it is a dll.

            M 1 Reply Last reply
            1
            • piervalliP piervalli

              @maverick13

              Build only not run, because it is a dll.

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

              @piervalli

              Okay. I did that, copied the dll into the data directory of the installer directory, and then went to run the Test.exe, and it doesn't crash anymore when sending, although now it just won't send..once again sorry and you might not know why, but figured I'd just ask.

              edit: and it still works perfectly running it through Qt Creator. Just the issue running it from the Test.exe within the data directory of the installer, or when installing it and running it.

              piervalliP 1 Reply Last reply
              0
              • M maverick13

                @piervalli

                Okay. I did that, copied the dll into the data directory of the installer directory, and then went to run the Test.exe, and it doesn't crash anymore when sending, although now it just won't send..once again sorry and you might not know why, but figured I'd just ask.

                edit: and it still works perfectly running it through Qt Creator. Just the issue running it from the Test.exe within the data directory of the installer, or when installing it and running it.

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

                @maverick13

                Hi Usually, I use a log on file, so It is easy check the errors.

                Try to checks qInstallMessageHandler

                https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

                Haved you used windeployqt to extraxt the dll?

                M 1 Reply Last reply
                1
                • piervalliP piervalli

                  @maverick13

                  Hi Usually, I use a log on file, so It is easy check the errors.

                  Try to checks qInstallMessageHandler

                  https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

                  Haved you used windeployqt to extraxt the dll?

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

                  @piervalli

                  Hi,

                  I have used windeploy to extract the dll.

                  Also, I know this is not the logging you had suggested, but I was having some trouble implementing it and wanted to get something.

                  I added some message box logs within the demo application, and I found out where it is hanging up, although I do not understand how/why..

                  This is within the .cpp of the demo program. It is in the slot for pressing the send button, to begin sending the email.

                      errorMessage("connecting to host");
                      smtp.connectToHost();
                      errorMessage(QString::fromStdString(std::to_string(smtp.waitForReadyConnected())));
                      if (!smtp.waitForReadyConnected())
                      {
                          errorMessage("Connection Failed");
                          return;
                      }
                  
                      errorMessage("authenticating");
                      smtp.login(user, password);
                      if (!smtp.waitForAuthenticated())
                      {
                          errorMessage("Authentification Failed");
                          return;
                      }
                  

                  The first box pops up telling me we are about to connect to the host, and then the second one which is returning the bool value of the waitForReadyConnect() function never returns.

                  The code for that function is (waitForReadyConnect())

                  bool SmtpClient::waitForReadyConnected(int msec) {
                      if (state == UnconnectedState)
                          return false;
                  
                      if (isReadyConnected)
                          return true;
                  
                      waitForEvent(msec, SIGNAL(readyConnected()));
                  
                      return isReadyConnected;
                  }
                  

                  waitForEvent()

                  void SmtpClient::waitForEvent(int msec, const char *successSignal)
                  {
                      QEventLoop loop;
                      QObject::connect(this, successSignal, &loop, SLOT(quit()));
                      QObject::connect(this, SIGNAL(error(SmtpClient::SmtpError)), &loop, SLOT(quit()));
                  
                      if(msec > 0)
                      {
                          QTimer timer;
                          timer.setSingleShot(true);
                          connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
                          timer.start(msec);
                      }
                  
                      loop.exec();
                  }
                  

                  I assume this has to be some issue with what I am doing since this repository has been used widely with no known issues like what I am experiencing.

                  I also double checked, again, the values I am using and they are

                  SMTP Server: smtp.gmail.com
                  Port Number: 465
                  Email: myemail@gmail.com
                  Password: my OTP

                  I assume there are not any issues with the credentials being I use them when running through Qt Creator and they work just fine, then once it is installed on my machine it seems to never connect to the host...not sure if the logging would really assist here being it does not even get to the point where an error message will be logged..

                  JonBJ 1 Reply Last reply
                  0
                  • M maverick13

                    @piervalli

                    Hi,

                    I have used windeploy to extract the dll.

                    Also, I know this is not the logging you had suggested, but I was having some trouble implementing it and wanted to get something.

                    I added some message box logs within the demo application, and I found out where it is hanging up, although I do not understand how/why..

                    This is within the .cpp of the demo program. It is in the slot for pressing the send button, to begin sending the email.

                        errorMessage("connecting to host");
                        smtp.connectToHost();
                        errorMessage(QString::fromStdString(std::to_string(smtp.waitForReadyConnected())));
                        if (!smtp.waitForReadyConnected())
                        {
                            errorMessage("Connection Failed");
                            return;
                        }
                    
                        errorMessage("authenticating");
                        smtp.login(user, password);
                        if (!smtp.waitForAuthenticated())
                        {
                            errorMessage("Authentification Failed");
                            return;
                        }
                    

                    The first box pops up telling me we are about to connect to the host, and then the second one which is returning the bool value of the waitForReadyConnect() function never returns.

                    The code for that function is (waitForReadyConnect())

                    bool SmtpClient::waitForReadyConnected(int msec) {
                        if (state == UnconnectedState)
                            return false;
                    
                        if (isReadyConnected)
                            return true;
                    
                        waitForEvent(msec, SIGNAL(readyConnected()));
                    
                        return isReadyConnected;
                    }
                    

                    waitForEvent()

                    void SmtpClient::waitForEvent(int msec, const char *successSignal)
                    {
                        QEventLoop loop;
                        QObject::connect(this, successSignal, &loop, SLOT(quit()));
                        QObject::connect(this, SIGNAL(error(SmtpClient::SmtpError)), &loop, SLOT(quit()));
                    
                        if(msec > 0)
                        {
                            QTimer timer;
                            timer.setSingleShot(true);
                            connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
                            timer.start(msec);
                        }
                    
                        loop.exec();
                    }
                    

                    I assume this has to be some issue with what I am doing since this repository has been used widely with no known issues like what I am experiencing.

                    I also double checked, again, the values I am using and they are

                    SMTP Server: smtp.gmail.com
                    Port Number: 465
                    Email: myemail@gmail.com
                    Password: my OTP

                    I assume there are not any issues with the credentials being I use them when running through Qt Creator and they work just fine, then once it is installed on my machine it seems to never connect to the host...not sure if the logging would really assist here being it does not even get to the point where an error message will be logged..

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #10

                    @maverick13

                    which is returning the bool value of the waitForReadyConnect() function never returns

                    Your timer.setSingleShot() will never timeout or fire any signal since it is destroyed before loop.exec() is reached!

                    That may have nothing to do with why you never get success or error signals, but it's a start to fix that....

                    I assume there are not any issues with the credentials

                    You are trying to send emails using the Gmail smtp.gmail.com connector? Correct me if I am wrong but is it not the case that:

                    • You have (had?) to enable a setting in Gmail to allow this.
                    • If you have 2FA on your account you have to do more than just username+password.

                    Not to mention I think you have to have SSL stuff for your Qt app.

                    I think you say you have some system which works from Creator but not when "installed" or "deployed"? is the install/deploy to a different machine or using a different Gmail account? If everything is on one machine with one account I guess this may not apply.

                    M 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @maverick13

                      which is returning the bool value of the waitForReadyConnect() function never returns

                      Your timer.setSingleShot() will never timeout or fire any signal since it is destroyed before loop.exec() is reached!

                      That may have nothing to do with why you never get success or error signals, but it's a start to fix that....

                      I assume there are not any issues with the credentials

                      You are trying to send emails using the Gmail smtp.gmail.com connector? Correct me if I am wrong but is it not the case that:

                      • You have (had?) to enable a setting in Gmail to allow this.
                      • If you have 2FA on your account you have to do more than just username+password.

                      Not to mention I think you have to have SSL stuff for your Qt app.

                      I think you say you have some system which works from Creator but not when "installed" or "deployed"? is the install/deploy to a different machine or using a different Gmail account? If everything is on one machine with one account I guess this may not apply.

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

                      Hi @JonB ,

                      So I believe the code that I posted (excluding the error messages) is as it should be, although I could be wrong being you are bringing up a valid point. The only reason I believe this, is because @piervalli has used the same repository (https://github.com/bluetiger9/SmtpClient-for-Qt) and it seems to be used very widely within Qt for sending emails.

                      I think you say you have some system which works from Creator but not when "installed" or "deployed"?

                      Correct.

                      is the install/deploy to a different machine or using a different Gmail account? If everything is on one machine with one account I guess this may not apply.

                      Negative, although good thought. I actually have set up everything you talked about here (minus 2FA):

                      • You have (had?) to enable a setting in Gmail to allow this.
                      • If you have 2FA on your account you have to do more than just username+password.

                      I set up a one time password in order to have a random string and it works perfectly, as you had brought up within Creator with the same credentials (I have them within a demo_vars.h file, as it is used in the GitHub Repository). So there should not be an issue with that I don't think.

                      JonBJ 1 Reply Last reply
                      0
                      • M maverick13

                        Hi @JonB ,

                        So I believe the code that I posted (excluding the error messages) is as it should be, although I could be wrong being you are bringing up a valid point. The only reason I believe this, is because @piervalli has used the same repository (https://github.com/bluetiger9/SmtpClient-for-Qt) and it seems to be used very widely within Qt for sending emails.

                        I think you say you have some system which works from Creator but not when "installed" or "deployed"?

                        Correct.

                        is the install/deploy to a different machine or using a different Gmail account? If everything is on one machine with one account I guess this may not apply.

                        Negative, although good thought. I actually have set up everything you talked about here (minus 2FA):

                        • You have (had?) to enable a setting in Gmail to allow this.
                        • If you have 2FA on your account you have to do more than just username+password.

                        I set up a one time password in order to have a random string and it works perfectly, as you had brought up within Creator with the same credentials (I have them within a demo_vars.h file, as it is used in the GitHub Repository). So there should not be an issue with that I don't think.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #12

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

                        So I believe the code that I posted (excluding the error messages) is as it should be, although I could be wrong being you are bringing up a valid point. The only reason I believe this, is because @piervalli has used the same repository (https://github.com/bluetiger9/SmtpClient-for-Qt) and it seems to be used very widely within Qt for sending emails.

                        If by "the code that I posted" you include the if (msec > 0) { ... } then it is "wrong" in the sense that you will never get a timeout to terminate the later loop.exec(). Maybe other users never needed a timeout because they always got success/error signals instead? (Or they did not get as far as waitForEvent().) But you say you "hang"/never return. Why do you think that is? Why don't you move the QTimer timer; statement to above the if(msec > 0) to see what happens? You can always move it back if you think I am wrong and they are right.... [EXTRA: Could you post the link to the exact file you are copying the timer.setSingleShot(true); code from please? Thanks.]

                        Next thing. You are calling waitForReadyConnected() twice. Why is that? Might your waitForReadyConnected() return on first call but not on second call? If you got the successful signal once would it get emitted the second time?

                        Next thing. What sets isReadyConnected = true;? I don't see that anywhere in the code you post.

                        Maybe this stuff is not to do with your problem. But I sure can't figure the code you show as-is, certainly for your "hanging" case.

                        M 2 Replies Last reply
                        0
                        • JonBJ JonB

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

                          So I believe the code that I posted (excluding the error messages) is as it should be, although I could be wrong being you are bringing up a valid point. The only reason I believe this, is because @piervalli has used the same repository (https://github.com/bluetiger9/SmtpClient-for-Qt) and it seems to be used very widely within Qt for sending emails.

                          If by "the code that I posted" you include the if (msec > 0) { ... } then it is "wrong" in the sense that you will never get a timeout to terminate the later loop.exec(). Maybe other users never needed a timeout because they always got success/error signals instead? (Or they did not get as far as waitForEvent().) But you say you "hang"/never return. Why do you think that is? Why don't you move the QTimer timer; statement to above the if(msec > 0) to see what happens? You can always move it back if you think I am wrong and they are right.... [EXTRA: Could you post the link to the exact file you are copying the timer.setSingleShot(true); code from please? Thanks.]

                          Next thing. You are calling waitForReadyConnected() twice. Why is that? Might your waitForReadyConnected() return on first call but not on second call? If you got the successful signal once would it get emitted the second time?

                          Next thing. What sets isReadyConnected = true;? I don't see that anywhere in the code you post.

                          Maybe this stuff is not to do with your problem. But I sure can't figure the code you show as-is, certainly for your "hanging" case.

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

                          @JonB

                          [EXTRA: Could you post the link to the exact file you are copying the timer.setSingleShot(true); code from please? Thanks.]

                          Here is the .cpp for that method:

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

                          You are calling waitForReadyConnected() twice. Why is that?

                          I called it twice as I was trying to implement message boxes as a "form" of debugging because I couldn't get my logging utility to work, and was experiencing some issues with qInstallMessageHandler, and wanted to try to debug ASAP. Regardless if it is hung up on the first call within the message box, or if I took that call out, it still is hung up on that call and it is an unexpected result, as it should return (unless your hunch is right)

                          Next thing. What sets isReadyConnected = true;? I don't see that anywhere in the code you post.

                          isReadyConnected is set to false in the constructor (https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/src/smtpclient.cpp#L34), and then set to true in changeState(SmtpClient::ClientState state) (https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/src/smtpclient.cpp#L300).

                          I didn't copy in the whole file, being it is cumbersome, but I will attach the GitHub link below to the specific .cpp, as it yields the same result just via GitHub.

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

                          If by "the code that I posted" you include the if (msec > 0) { ... } then it is "wrong" in the sense that you will never get a timeout to terminate the later loop.exec(). Maybe other users never needed a timeout because they always got success/error signals instead? (Or they did not get as far as waitForEvent().) But you say you "hang"/never return. Why do you think that is? Why don't you move the QTimer timer; statement to above the if(msec > 0) to see what happens? You can always move it back if you think I am wrong and they are right....

                          I am going to try this now! Thanks. I wasn't saying you were wrong, I was just under the assumption that the repository worked so I was not sure if changing anything would help, but I will definitely try this right now and update this post with the result.

                          JonBJ 1 Reply Last reply
                          0
                          • M maverick13

                            @JonB

                            [EXTRA: Could you post the link to the exact file you are copying the timer.setSingleShot(true); code from please? Thanks.]

                            Here is the .cpp for that method:

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

                            You are calling waitForReadyConnected() twice. Why is that?

                            I called it twice as I was trying to implement message boxes as a "form" of debugging because I couldn't get my logging utility to work, and was experiencing some issues with qInstallMessageHandler, and wanted to try to debug ASAP. Regardless if it is hung up on the first call within the message box, or if I took that call out, it still is hung up on that call and it is an unexpected result, as it should return (unless your hunch is right)

                            Next thing. What sets isReadyConnected = true;? I don't see that anywhere in the code you post.

                            isReadyConnected is set to false in the constructor (https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/src/smtpclient.cpp#L34), and then set to true in changeState(SmtpClient::ClientState state) (https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/src/smtpclient.cpp#L300).

                            I didn't copy in the whole file, being it is cumbersome, but I will attach the GitHub link below to the specific .cpp, as it yields the same result just via GitHub.

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

                            If by "the code that I posted" you include the if (msec > 0) { ... } then it is "wrong" in the sense that you will never get a timeout to terminate the later loop.exec(). Maybe other users never needed a timeout because they always got success/error signals instead? (Or they did not get as far as waitForEvent().) But you say you "hang"/never return. Why do you think that is? Why don't you move the QTimer timer; statement to above the if(msec > 0) to see what happens? You can always move it back if you think I am wrong and they are right....

                            I am going to try this now! Thanks. I wasn't saying you were wrong, I was just under the assumption that the repository worked so I was not sure if changing anything would help, but I will definitely try this right now and update this post with the result.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #14

                            @maverick13
                            Rmove this line:

                            errorMessage(QString::fromStdString(std::to_string(smtp.waitForReadyConnected())));

                            For the timer, you can either move it outside the { .. }s or you could call the static QTimer::singleShot() (whichever overload for your slot stuff) to avoid the scope issue. I suggest their code was not tested when the timeout was required!

                            This might hopefully aid debugging whatever the bad issue is.

                            1 Reply Last reply
                            1
                            • JonBJ JonB

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

                              So I believe the code that I posted (excluding the error messages) is as it should be, although I could be wrong being you are bringing up a valid point. The only reason I believe this, is because @piervalli has used the same repository (https://github.com/bluetiger9/SmtpClient-for-Qt) and it seems to be used very widely within Qt for sending emails.

                              If by "the code that I posted" you include the if (msec > 0) { ... } then it is "wrong" in the sense that you will never get a timeout to terminate the later loop.exec(). Maybe other users never needed a timeout because they always got success/error signals instead? (Or they did not get as far as waitForEvent().) But you say you "hang"/never return. Why do you think that is? Why don't you move the QTimer timer; statement to above the if(msec > 0) to see what happens? You can always move it back if you think I am wrong and they are right.... [EXTRA: Could you post the link to the exact file you are copying the timer.setSingleShot(true); code from please? Thanks.]

                              Next thing. You are calling waitForReadyConnected() twice. Why is that? Might your waitForReadyConnected() return on first call but not on second call? If you got the successful signal once would it get emitted the second time?

                              Next thing. What sets isReadyConnected = true;? I don't see that anywhere in the code you post.

                              Maybe this stuff is not to do with your problem. But I sure can't figure the code you show as-is, certainly for your "hanging" case.

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

                              @JonB

                              Why don't you move the QTimer timer; statement to above the if(msec > 0) to see what happens?

                              When doing this I ended up getting a return value of 0 from the message box, as pictured below.

                              643508f4-6152-413a-afcb-bab80a292a21-image.png

                              You are calling waitForReadyConnected() twice. Why is that?

                              I explained why in my previous reply, but I took it out and it yielded the same result (it just printed out the errorMessage(...) as put in the demo by bluetiger saying "Connection Failed". The reason I did not see the original one before this was probably due to what you had said prior about the QTimer timer neededing to be outside the loop.

                              c3525ce5-fda9-4ea0-9c52-be9691e74de0-image.png

                              The code to the demo that I am using is here

                              https://github.com/bluetiger9/SmtpClient-for-Qt/tree/v2.0/demos/demo2

                              The specific file/line we were speaking about with the message boxes is here:

                              https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/demos/demo2/sendemail.cpp#L125

                              This all still works within Qt Creator, but not when creating an installer package of the application, and then installing it on my machine (the same machine in which I am running it via Qt Creator, and developing on). I have also tried to install and run on different machines, and it yields the same unexpected result.

                              JonBJ 1 Reply Last reply
                              0
                              • M maverick13

                                @JonB

                                Why don't you move the QTimer timer; statement to above the if(msec > 0) to see what happens?

                                When doing this I ended up getting a return value of 0 from the message box, as pictured below.

                                643508f4-6152-413a-afcb-bab80a292a21-image.png

                                You are calling waitForReadyConnected() twice. Why is that?

                                I explained why in my previous reply, but I took it out and it yielded the same result (it just printed out the errorMessage(...) as put in the demo by bluetiger saying "Connection Failed". The reason I did not see the original one before this was probably due to what you had said prior about the QTimer timer neededing to be outside the loop.

                                c3525ce5-fda9-4ea0-9c52-be9691e74de0-image.png

                                The code to the demo that I am using is here

                                https://github.com/bluetiger9/SmtpClient-for-Qt/tree/v2.0/demos/demo2

                                The specific file/line we were speaking about with the message boxes is here:

                                https://github.com/bluetiger9/SmtpClient-for-Qt/blob/v2.0/demos/demo2/sendemail.cpp#L125

                                This all still works within Qt Creator, but not when creating an installer package of the application, and then installing it on my machine (the same machine in which I am running it via Qt Creator, and developing on). I have also tried to install and run on different machines, and it yields the same unexpected result.

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #16

                                @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 1 Reply Last reply
                                1
                                • 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 Offline
                                    JonBJ Offline
                                    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 Offline
                                        JonBJ Offline
                                        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

                                          • Login

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