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
QtWS25 Last Chance

Send attachment by email

Scheduled Pinned Locked Moved Solved General and Desktop
27 Posts 5 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J JonB
    4 Jun 2021, 09:39

    @artwaw
    Sorry I don't agree with you or see the connection. Qt as distributed does not come with particular support for either IMAP or SMTP. SMTP code is required to send mail, and that is quite different code from IMAP. The OP will need SMTP code, and might as well use libcurl as that seems to be C++ and "standard". There is a lot to SMTP code and he won't want to write it from scratch. Whatever useful the IMAP has for Qt should be small compared to what is required for SMTP itself.

    However, if you say there are some ideas in the IMAP code you reference he might want to look at from the Qt perspective so be it.

    I would search for qt5 SMTP. There are a few hits out there. Maybe https://morf.lv/simple-tls-ssl-smtp-client-for-qt5 is useful, or I see there is cutelyst at https://github.com/cutelyst/simple-mail which says it is for Qt. Actually this looks like it might be quite appropriate:

    The SimpleMail is small library writen for Qt 5 or 6 (C++11) that allows applications to send complex emails (plain text, html, attachments, inline files, etc.) using the Simple Mail Transfer Protocol (SMTP).

    It includes support for the user's question about attachment.

    M Offline
    M Offline
    Marcus Barnet
    wrote on 4 Jun 2021, 14:06 last edited by
    #8

    @JonB said in Send attachment by email:

    @artwaw
    Sorry I don't agree with you or see the connection. Qt as distributed does not come with particular support for either IMAP or SMTP. SMTP code is required to send mail, and that is quite different code from IMAP. The OP will need SMTP code, and might as well use libcurl as that seems to be C++ and "standard". There is a lot to SMTP code and he won't want to write it from scratch. Whatever useful the IMAP has for Qt should be small compared to what is required for SMTP itself.

    However, if you say there are some ideas in the IMAP code you reference he might want to look at from the Qt perspective so be it.

    I would search for qt5 SMTP. There are a few hits out there. Maybe https://morf.lv/simple-tls-ssl-smtp-client-for-qt5 is useful, or I see there is cutelyst at https://github.com/cutelyst/simple-mail which says it is for Qt. Actually this looks like it might be quite appropriate:

    The SimpleMail is small library writen for Qt 5 or 6 (C++11) that allows applications to send complex emails (plain text, html, attachments, inline files, etc.) using the Simple Mail Transfer Protocol (SMTP).

    It includes support for the user's question about attachment.

    Very interesting! I checked these two solutions and they seem to be very useful for what I would like to do!
    I'm going to explore better the second one since it looks like easier to implement.

    I'll keep you updated during next days! Thank you!!

    1 Reply Last reply
    1
    • M Offline
      M Offline
      Marcus Barnet
      wrote on 4 Jun 2021, 22:27 last edited by
      #9

      The SmtpClient-for-Qt worked like a charm!

      Thanks for the support!

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Marcus Barnet
        wrote on 7 Jun 2021, 07:30 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.

        J J 2 Replies Last reply 7 Jun 2021, 07:42
        0
        • M Marcus Barnet
          7 Jun 2021, 07:30

          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 Offline
          J Offline
          JonB
          wrote on 7 Jun 2021, 07:42 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 1 Reply Last reply 7 Jun 2021, 11:00
          1
          • M Marcus Barnet
            7 Jun 2021, 07:30

            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 Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 7 Jun 2021, 07:55 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 7 Jun 2021, 08:07 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 7 Jun 2021, 08:18 last edited by Marcus Barnet 6 Jul 2021, 08:25
                #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.

                J 1 Reply Last reply 7 Jun 2021, 08:25
                0
                • M Marcus Barnet
                  7 Jun 2021, 08:18

                  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.

                  J Offline
                  J Offline
                  JonB
                  wrote on 7 Jun 2021, 08:25 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 7 Jun 2021, 08:30 last edited by Marcus Barnet 6 Jul 2021, 08:31
                    #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.

                    J 1 Reply Last reply 7 Jun 2021, 08:34
                    0
                    • M Marcus Barnet
                      7 Jun 2021, 08:30

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

                      J Offline
                      J Offline
                      JonB
                      wrote on 7 Jun 2021, 08:34 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 7 Jun 2021, 10:55 last edited by Marcus Barnet 6 Jul 2021, 10:59
                        #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
                        • J JonB
                          7 Jun 2021, 07:42

                          @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 Offline
                          J Offline
                          J.Hilk
                          Moderators
                          wrote on 7 Jun 2021, 11:00 last edited by J.Hilk 6 Jul 2021, 11:01
                          #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 7 Jun 2021, 12:50 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 J 2 Replies Last reply 7 Jun 2021, 13:02
                            0
                            • M Marcus Barnet
                              7 Jun 2021, 12:50

                              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 Offline
                              J Offline
                              J.Hilk
                              Moderators
                              wrote on 7 Jun 2021, 13:02 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
                                7 Jun 2021, 12:50

                                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 Offline
                                J Offline
                                JonB
                                wrote on 7 Jun 2021, 13:04 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 7 Jun 2021, 19:31 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 19 Jan 2024, 10:28 last edited by
                                    #24

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

                                    J 1 Reply Last reply 19 Jan 2024, 14:12
                                    0
                                    • L Long Vu Ngoc
                                      19 Jan 2024, 10:28

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

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 19 Jan 2024, 14:12 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 19 Jan 2024, 14:14
                                      0
                                      • J JonB
                                        19 Jan 2024, 14:12

                                        @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 19 Jan 2024, 14:14 last edited by
                                        #26

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

                                        J 1 Reply Last reply 19 Jan 2024, 14:18
                                        0
                                        • L Long Vu Ngoc
                                          19 Jan 2024, 14:14

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

                                          J Offline
                                          J Offline
                                          JonB
                                          wrote on 19 Jan 2024, 14:18 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