Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Send attachment by email
Forum Updated to NodeBB v4.3 + New Features

Send attachment by email

Scheduled Pinned Locked Moved Solved General and Desktop
27 Posts 5 Posters 4.2k Views 3 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 Offline
    M Offline
    Marcus Barnet
    wrote on last edited by
    #10

    I'm sorry to re-open this topic, but I found out that there is an issue with my code.

    Everything works fine on the laptop I use to develop the code with QtCreator since I'm able to successfully send the emails with the SmtpClient-for-Qt library. I run the program from a folder I created by including all the DLLs that are necessary to run all the functions I used.

    The program runs and works fine also on other laptops, but when I try to send emails, I receveid the error: "cannot connect to the host".

    It was very strange to me since the same program runs correctly on my laptop, so I think the problem should be connected to some library or DLL that the program is able to find on my development laptop but it is not able to find on other computers even if I get no DLL missing errors when I start it.

    How do you think I can solve the problem?

    SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
    ..
    smtp.connectToHost();
    smtp.login();
    smtp.sendMail(message);
    

    I copied the SMTPEmail.dll into the program folder.
    Should I set some specific configuration during the build in QtCreator?

    I used several libraries and they perfectly work without problems!
    Only the SmptClient library is giving the issue.

    P.S. The same program is able to correctly send email via smtp by using curl (curl.exe --ssl-reqd -k --url smtp://smtp.gmail.com:587) on every laptop.

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • M Marcus Barnet

      I'm sorry to re-open this topic, but I found out that there is an issue with my code.

      Everything works fine on the laptop I use to develop the code with QtCreator since I'm able to successfully send the emails with the SmtpClient-for-Qt library. I run the program from a folder I created by including all the DLLs that are necessary to run all the functions I used.

      The program runs and works fine also on other laptops, but when I try to send emails, I receveid the error: "cannot connect to the host".

      It was very strange to me since the same program runs correctly on my laptop, so I think the problem should be connected to some library or DLL that the program is able to find on my development laptop but it is not able to find on other computers even if I get no DLL missing errors when I start it.

      How do you think I can solve the problem?

      SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
      ..
      smtp.connectToHost();
      smtp.login();
      smtp.sendMail(message);
      

      I copied the SMTPEmail.dll into the program folder.
      Should I set some specific configuration during the build in QtCreator?

      I used several libraries and they perfectly work without problems!
      Only the SmptClient library is giving the issue.

      P.S. The same program is able to correctly send email via smtp by using curl (curl.exe --ssl-reqd -k --url smtp://smtp.gmail.com:587) on every laptop.

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

      @Marcus-Barnet
      Here are several sundry possibilities:

      • Does the target have the OpenSSL libraries/support installed, which I understand is required for Qt SSL support?
      • Does the SMTP DLL have all its dependencies on the target machine (maybe run Dependency Walker on it)?
      • You are supposed to deploy a Qt program to a target machine, since it is not in the same state as a Qt development machine. Did you do that (e.g. windeployqt)?
      J.HilkJ 1 Reply Last reply
      1
      • M Marcus Barnet

        I'm sorry to re-open this topic, but I found out that there is an issue with my code.

        Everything works fine on the laptop I use to develop the code with QtCreator since I'm able to successfully send the emails with the SmtpClient-for-Qt library. I run the program from a folder I created by including all the DLLs that are necessary to run all the functions I used.

        The program runs and works fine also on other laptops, but when I try to send emails, I receveid the error: "cannot connect to the host".

        It was very strange to me since the same program runs correctly on my laptop, so I think the problem should be connected to some library or DLL that the program is able to find on my development laptop but it is not able to find on other computers even if I get no DLL missing errors when I start it.

        How do you think I can solve the problem?

        SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
        ..
        smtp.connectToHost();
        smtp.login();
        smtp.sendMail(message);
        

        I copied the SMTPEmail.dll into the program folder.
        Should I set some specific configuration during the build in QtCreator?

        I used several libraries and they perfectly work without problems!
        Only the SmptClient library is giving the issue.

        P.S. The same program is able to correctly send email via smtp by using curl (curl.exe --ssl-reqd -k --url smtp://smtp.gmail.com:587) on every laptop.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #12

        @Marcus-Barnet
        if you're using the online installer, than you can download the correct openssl dlls there directly

        d4f9706f-11d4-4a5a-a080-1e28c446dfc7-image.png


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Marcus Barnet
          wrote on last edited by
          #13

          Thank you for the support!
          The program worked fine on every laptop without errors, so I think all the previos libraries were correctly installed.
          I'm only having the problem with the SmtpClient-for-Qt.

          I used windeployqt to create the folder by following the instruction on https://doc.qt.io/qt-5/windows-deployment.html

          I'm trying to run Dependency Walker, but it as soon as I loaded the SMTPEmail.dll it got stuck.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Marcus Barnet
            wrote on last edited by Marcus Barnet
            #14

            This is the output of Dependency Walker:

            Error: At least one required implicit or forwarded dependency was not found.
            Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
            Error: Modules with different CPU types were found.
            Error: A circular dependency was detected.
            Warning: At least one delay-load dependency module was not found.
            Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

            However, I'm able to run the program from its standalone folder from my development laptop.
            The problem occurs when I need to run it on other laptops even if I copy the whole folder.

            JonBJ 1 Reply Last reply
            0
            • M Marcus Barnet

              This is the output of Dependency Walker:

              Error: At least one required implicit or forwarded dependency was not found.
              Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
              Error: Modules with different CPU types were found.
              Error: A circular dependency was detected.
              Warning: At least one delay-load dependency module was not found.
              Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

              However, I'm able to run the program from its standalone folder from my development laptop.
              The problem occurs when I need to run it on other laptops even if I copy the whole folder.

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

              @Marcus-Barnet said in Send attachment by email:

              Error: Modules with different CPU types were found.

              I don't know if this great. Compare the DW output with the machine where it does work?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Marcus Barnet
                wrote on last edited by Marcus Barnet
                #16

                @JonB said in Send attachment by email:

                @Marcus-Barnet said in Send attachment by email:

                Error: Modules with different CPU types were found.

                I don't know if this great. Compare the DW output with the machine where it does work?

                The output I posted has been generated by running DW from my delopment computer. I picked up the DLL from the folder I use to run the program standalone.

                I really can't understand since the program works fine if I run it both from the QtCreator run utility and from the folder I created on my development computer where I copied all the DLLs.

                JonBJ 1 Reply Last reply
                0
                • M Marcus Barnet

                  @JonB said in Send attachment by email:

                  @Marcus-Barnet said in Send attachment by email:

                  Error: Modules with different CPU types were found.

                  I don't know if this great. Compare the DW output with the machine where it does work?

                  The output I posted has been generated by running DW from my delopment computer. I picked up the DLL from the folder I use to run the program standalone.

                  I really can't understand since the program works fine if I run it both from the QtCreator run utility and from the folder I created on my development computer where I copied all the DLLs.

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

                  @Marcus-Barnet
                  I don't think I understand. Why are you testing the running one and not the bad one?

                  Can you please state clearly where it does not work? You said earlier it does not work on other machines?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Marcus Barnet
                    wrote on last edited by Marcus Barnet
                    #18

                    The developed program is very simple: it connects to a MySQL database and retrieves some data depending on the user's input.
                    The program works fine both on my development laptop and on ALL other laptops.
                    To distribute the program on all other laptops, I created a folder where I put the executable and also all the required DLLs from QT and from the MySQL library.
                    The executable works fine both on my computer and on the other laptops.

                    Two days ago, I decided to include the SmtpClient-for-Qt library as you suggested in this topic but I need to provide the user to send some information by email.

                    I integrated the smtp code in my program, I built it and I put the executable in the folder used to redistribute the program together with the SMTPEmail.dll (If I run the executable without this DLL, it gives me the missing DLL error for SMTPEmail.dll and for Qt5Network.dll, so I added them to the folder ).

                    Now, the executable works fine and correctly send emails IF I run it from the folder ON MY laptop.
                    The executable opens and runs fine also on all other computers but WHEN the user tries to SEND the email, it gives the error: "CANNOT connect to host".

                    So the program runs correctly on ALL the laptops, but it gives the connection error when the user tries to send email from all other laptops (it works fine only on my development laptop).

                    At the beginning, I thought about a network error, but all the laptops (included my laptop) are in the same network.

                    This is the file list for the folder from where I run the program (it's the same both for my laptop and the other ones):

                    27/05/2021  00:22    <DIR>          email
                    07/03/2021  19:37    <DIR>          imageformats
                    13/07/2017  13:29         4,879,360 libmysql.dll
                    06/06/2021  21:11            16,996 myapp.res
                    28/05/2021  22:43    <DIR>          pics
                    07/03/2021  19:37    <DIR>          platforms
                    06/06/2021  23:27         4,460,032 PUMP.exe
                    17/05/2021  21:54           140,242 pump_db (1).sql
                    20/05/2021  08:25           218,138 pump_db_20_05_21.sql
                    11/05/2020  10:46         5,998,712 Qt5Core.dll
                    11/05/2020  10:47         7,085,176 Qt5Gui.dll
                    11/05/2020  10:47         1,349,240 Qt5Network.dll
                    11/05/2020  10:47           208,504 Qt5Sql.dll
                    11/05/2020  17:05           329,848 Qt5Svg.dll
                    11/05/2020  10:47         5,516,920 Qt5Widgets.dll
                    05/06/2021  00:21            74,240 SMTPEmail.dll
                    07/03/2021  19:37    <DIR>          sqldrivers
                    07/03/2021  19:37    <DIR>          styles
                    
                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Marcus-Barnet
                      Here are several sundry possibilities:

                      • Does the target have the OpenSSL libraries/support installed, which I understand is required for Qt SSL support?
                      • Does the SMTP DLL have all its dependencies on the target machine (maybe run Dependency Walker on it)?
                      • You are supposed to deploy a Qt program to a target machine, since it is not in the same state as a Qt development machine. Did you do that (e.g. windeployqt)?
                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by J.Hilk
                      #19

                      Like @JonB and I said in Send attachment by email:

                      Does the target have the OpenSSL libraries/support installed, which I understand is required for Qt SSL support?

                      Your open SSL DLLs are missing from the installation folder, they are apparently part of your system path (on your development pc) but you can't guarantee that for all systems-> The reason why it fails on other machines.
                      Provide them.

                      26752d2d-0799-4661-b9aa-3943a4e3398e-image.png


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      3
                      • M Offline
                        M Offline
                        Marcus Barnet
                        wrote on last edited by
                        #20

                        I'm going to check this even if I receive no errors about these missing DDLs when I run the program on the other systems.
                        Shouldn't I receive an error as soon as I try to run the program?

                        J.HilkJ JonBJ 2 Replies Last reply
                        0
                        • M Marcus Barnet

                          I'm going to check this even if I receive no errors about these missing DDLs when I run the program on the other systems.
                          Shouldn't I receive an error as soon as I try to run the program?

                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #21

                          @Marcus-Barnet said in Send attachment by email:

                          I'm going to check this even if I receive no errors about these missing DDLs when I run the program on the other systems.
                          Shouldn't I receive an error as soon as I try to run the program?

                          no, in this case its a silent fail,

                          silent, in so much as, you should (technically) a get a console output about a failed loading


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          1 Reply Last reply
                          1
                          • M Marcus Barnet

                            I'm going to check this even if I receive no errors about these missing DDLs when I run the program on the other systems.
                            Shouldn't I receive an error as soon as I try to run the program?

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

                            @Marcus-Barnet said in Send attachment by email:

                            Shouldn't I receive an error as soon as I try to run the program?

                            Not if the OpenSSL stuff is dynamically loaded (e.g. when the first call is made to send using encryption) instead of statically linked. Which may be what @J-Hilk is indicating is the case.

                            1 Reply Last reply
                            1
                            • M Offline
                              M Offline
                              Marcus Barnet
                              wrote on last edited by
                              #23

                              Thank you, guys!

                              Now, it works fine! I copied both files to the folder and the program runs fine on all laptops.

                              1 Reply Last reply
                              1
                              • L Offline
                                L Offline
                                Long Vu Ngoc
                                wrote on last edited by
                                #24

                                @Marcus-Barnet Hello, Can I ask you something about the topic?

                                JonBJ 1 Reply Last reply
                                0
                                • L Long Vu Ngoc

                                  @Marcus-Barnet Hello, Can I ask you something about the topic?

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

                                  @Long-Vu-Ngoc That user likely won't be around. Just ask your question. Create a new topic probably.

                                  L 1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @Long-Vu-Ngoc That user likely won't be around. Just ask your question. Create a new topic probably.

                                    L Offline
                                    L Offline
                                    Long Vu Ngoc
                                    wrote on last edited by
                                    #26

                                    @JonB Here is my topic
                                    https://forum.qt.io/topic/153943/how-to-send-email-from-my-application?_=1705673637272

                                    JonBJ 1 Reply Last reply
                                    0
                                    • L Long Vu Ngoc

                                      @JonB Here is my topic
                                      https://forum.qt.io/topic/153943/how-to-send-email-from-my-application?_=1705673637272

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

                                      @Long-Vu-Ngoc I know, I saw it. Stick to that, you won't get any more help from here.

                                      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