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. is there anyway to Send Email to someone in Qt?
Forum Updated to NodeBB v4.3 + New Features

is there anyway to Send Email to someone in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
48 Posts 12 Posters 29.3k 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.
  • O opengpu
    25 Apr 2019, 09:08

    i saw there is the setting at some email site; there are:
    POP3 server
    SMTP server
    IMAP server

    J Offline
    J Offline
    JonB
    wrote on 25 Apr 2019, 09:20 last edited by JonB
    #18

    @opengpu
    You seem to be making things pretty complicated for yourself, possibly because you have not read up on SMTP/POP3/IMAP.

    Your question is about sending emails, from your Qt app. For that all you need is SMTP client code in your app, and knowledge of which SMTP server you wish it to connect to send the email, e.g smtp.gmail.com if you have a Gmail account.

    POP3/IMAP are for retrieving emails from a server. You have never asked for that. Unless you now need that facility too, forget about them. You need SMTP client only.

    1 Reply Last reply
    5
    • O Offline
      O Offline
      opengpu
      wrote on 25 Apr 2019, 09:28 last edited by
      #19

      thanks for all. i google that protocol, and now i got it.

      J 1 Reply Last reply 25 Apr 2019, 09:37
      0
      • O opengpu
        25 Apr 2019, 09:28

        thanks for all. i google that protocol, and now i got it.

        J Offline
        J Offline
        JonB
        wrote on 25 Apr 2019, 09:37 last edited by JonB
        #20

        @opengpu
        BTW, I don't know if this will help you, but....

        In my case the users of my software specify & use there own SMTP server to connect to for sending email. Here is what my interafce looks like for them to specify the necessaries:

        0_1556184717892_smtpclient.png

        I don't know whether in your case you want the user to supply this information for their own SMTP email server, or whether you are supplying the server and hard-coding the values. Either way it shows the sort of parameters you will need to have in order to connect to the SMTP server.

        I program in Python/PyQt, not C++. So the SMTP client code I use is provided by a Python library, which won't be of any use to you. But either of the simple SMTP clients you are proposing to use will have a similar interface/parameters.

        O 1 Reply Last reply 25 Apr 2019, 10:17
        2
        • J JonB
          25 Apr 2019, 09:37

          @opengpu
          BTW, I don't know if this will help you, but....

          In my case the users of my software specify & use there own SMTP server to connect to for sending email. Here is what my interafce looks like for them to specify the necessaries:

          0_1556184717892_smtpclient.png

          I don't know whether in your case you want the user to supply this information for their own SMTP email server, or whether you are supplying the server and hard-coding the values. Either way it shows the sort of parameters you will need to have in order to connect to the SMTP server.

          I program in Python/PyQt, not C++. So the SMTP client code I use is provided by a Python library, which won't be of any use to you. But either of the simple SMTP clients you are proposing to use will have a similar interface/parameters.

          O Offline
          O Offline
          opengpu
          wrote on 25 Apr 2019, 10:17 last edited by
          #21

          @JonB thank you so much!
          actually i want to use email instead of instantMsg. i send from PC client , and the official email-client of some company like google will recieve that email and alert the user.

          O 1 Reply Last reply 25 Apr 2019, 10:33
          0
          • O opengpu
            25 Apr 2019, 10:17

            @JonB thank you so much!
            actually i want to use email instead of instantMsg. i send from PC client , and the official email-client of some company like google will recieve that email and alert the user.

            O Offline
            O Offline
            opengpu
            wrote on 25 Apr 2019, 10:33 last edited by
            #22

            and at common situation , email is fast enough when recieved after send?

            M 1 Reply Last reply 25 Apr 2019, 10:35
            0
            • O opengpu
              25 Apr 2019, 10:33

              and at common situation , email is fast enough when recieved after send?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 25 Apr 2019, 10:35 last edited by
              #23

              @opengpu
              Well in most cases, email comes very fast.
              But if your app is very, very, very far away, it might take a few minutes to get to
              destination.

              J 1 Reply Last reply 25 Apr 2019, 10:41
              0
              • M mrjj
                25 Apr 2019, 10:35

                @opengpu
                Well in most cases, email comes very fast.
                But if your app is very, very, very far away, it might take a few minutes to get to
                destination.

                J Offline
                J Offline
                JonB
                wrote on 25 Apr 2019, 10:41 last edited by
                #24

                @mrjj Are you talking about sending emails to Alpha Centauri? :)

                M 1 Reply Last reply 25 Apr 2019, 10:43
                3
                • J JonB
                  25 Apr 2019, 10:41

                  @mrjj Are you talking about sending emails to Alpha Centauri? :)

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 25 Apr 2019, 10:43 last edited by
                  #25

                  @JonB said

                  Alpha Centauri

                  Haha. that might take some time... ;)
                  Ok maybe i went too far with "very" :)

                  1 Reply Last reply
                  1
                  • R raven-worx
                    24 Apr 2019, 17:14

                    @opengpu
                    not directly, only with 3rd party libs:
                    https://github.com/cutelyst/simple-mail
                    https://github.com/bluetiger9/SmtpClient-for-Qt
                    ...
                    and a SMTP server of course.

                    or via IMAP server
                    http://trojita.flaska.net/

                    O Offline
                    O Offline
                    opengpu
                    wrote on 25 Apr 2019, 12:37 last edited by
                    #26

                    @raven-worx
                    after cmake and compile error in vs:
                    simple-mail-master\build\src\simplemail-qt5_autogen\include_Debug\EWIEGA46WW/moc_sender.cpp(197): error C2491: 'SimpleMail::Sender::staticMetaObject': definition of dllimport static data member not allowed

                    vs2017, x64,
                    Qt\5.12.3\msvc2017_64\lib\cmake\Qt5\Qt5Config.cmake

                    R 1 Reply Last reply 25 Apr 2019, 12:42
                    0
                    • O opengpu
                      25 Apr 2019, 12:37

                      @raven-worx
                      after cmake and compile error in vs:
                      simple-mail-master\build\src\simplemail-qt5_autogen\include_Debug\EWIEGA46WW/moc_sender.cpp(197): error C2491: 'SimpleMail::Sender::staticMetaObject': definition of dllimport static data member not allowed

                      vs2017, x64,
                      Qt\5.12.3\msvc2017_64\lib\cmake\Qt5\Qt5Config.cmake

                      R Offline
                      R Offline
                      raven-worx
                      Moderators
                      wrote on 25 Apr 2019, 12:42 last edited by
                      #27

                      @opengpu
                      i haven't written nor used those 3rd party libs, i just pointed them out.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      1
                      • O Offline
                        O Offline
                        opengpu
                        wrote on 26 Apr 2019, 09:25 last edited by
                        #28

                        thank you

                        1 Reply Last reply
                        0
                        • O Offline
                          O Offline
                          opengpu
                          wrote on 17 Jun 2019, 03:05 last edited by opengpu
                          #29

                          anyone ever used libcurl to send email to smtp server?how many milliseconds it need for sending mail one time?is it fast enough to send email by libcurl in mainThread?

                          i tried this one, it works. but it's slow, as it needs about 3000 milliseconds for sending email one time.
                          https://github.com/bluetiger9/SmtpClient-for-Qt

                          R 1 Reply Last reply 17 Jun 2019, 06:25
                          0
                          • O opengpu
                            17 Jun 2019, 03:05

                            anyone ever used libcurl to send email to smtp server?how many milliseconds it need for sending mail one time?is it fast enough to send email by libcurl in mainThread?

                            i tried this one, it works. but it's slow, as it needs about 3000 milliseconds for sending email one time.
                            https://github.com/bluetiger9/SmtpClient-for-Qt

                            R Offline
                            R Offline
                            raven-worx
                            Moderators
                            wrote on 17 Jun 2019, 06:25 last edited by
                            #30

                            @opengpu said in is there anyway to Send Email to someone in Qt?:

                            as it needs about 3000 milliseconds for sending email one time.

                            you mean 3000 ms till you've sent the email contents to the server?
                            or 3000 ms till you received it in the receivers mailbox?

                            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                            If you have a question please use the forum so others can benefit from the solution in the future

                            O 1 Reply Last reply 17 Jun 2019, 06:28
                            1
                            • R raven-worx
                              17 Jun 2019, 06:25

                              @opengpu said in is there anyway to Send Email to someone in Qt?:

                              as it needs about 3000 milliseconds for sending email one time.

                              you mean 3000 ms till you've sent the email contents to the server?
                              or 3000 ms till you received it in the receivers mailbox?

                              O Offline
                              O Offline
                              opengpu
                              wrote on 17 Jun 2019, 06:28 last edited by
                              #31

                              @raven-worx just the sent code complish

                              1 Reply Last reply
                              0
                              • O Offline
                                O Offline
                                opengpu
                                wrote on 17 Jun 2019, 06:29 last edited by
                                #32
                                    // First we need to create an SmtpClient object
                                    // We will use the Gmail's smtp server (smtp.gmail.com, port 465, ssl)
                                
                                    SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
                                
                                    // We need to set the username (your email address) and password
                                    // for smtp authentification.
                                
                                    smtp.setUser("your_email_address@host.com");
                                    smtp.setPassword("your_password");
                                
                                    // Now we create a MimeMessage object. This is the email.
                                
                                    MimeMessage message;
                                
                                    EmailAddress sender("your_email_address@host.com", "Your Name");
                                    message.setSender(&sender);
                                
                                    EmailAddress to("recipient@host.com", "Recipient's Name");
                                    message.addRecipient(&to);
                                
                                    message.setSubject("SmtpClient for Qt - Demo");
                                
                                    // Now add some text to the email.
                                    // First we create a MimeText object.
                                
                                    MimeText text;
                                
                                    text.setText("Hi,\nThis is a simple email message.\n");
                                
                                    // Now add it to the mail
                                
                                    message.addPart(&text);
                                
                                    // Now we can send the mail
                                
                                    if (!smtp.connectToHost()) {
                                        qDebug() << "Failed to connect to host!" << endl;
                                        return -1;
                                    }
                                
                                    if (!smtp.login()) {
                                        qDebug() << "Failed to login!" << endl;
                                        return -2;
                                    }
                                
                                    if (!smtp.sendMail(message)) {
                                        qDebug() << "Failed to send mail!" << endl;
                                        return -3;
                                    }
                                
                                    smtp.quit();
                                
                                1 Reply Last reply
                                1
                                • O Offline
                                  O Offline
                                  opengpu
                                  wrote on 17 Jun 2019, 06:30 last edited by
                                  #33

                                  the time before the 1st line between after the last line.

                                  R 1 Reply Last reply 18 Jun 2019, 17:06
                                  0
                                  • O opengpu
                                    17 Jun 2019, 06:30

                                    the time before the 1st line between after the last line.

                                    R Offline
                                    R Offline
                                    raven-worx
                                    Moderators
                                    wrote on 18 Jun 2019, 17:06 last edited by
                                    #34

                                    @opengpu
                                    does it help to keep the SmtpClient instance? instead of creating a new one everytime you send an email

                                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                    If you have a question please use the forum so others can benefit from the solution in the future

                                    O 1 Reply Last reply 19 Jun 2019, 07:51
                                    2
                                    • R raven-worx
                                      18 Jun 2019, 17:06

                                      @opengpu
                                      does it help to keep the SmtpClient instance? instead of creating a new one everytime you send an email

                                      O Offline
                                      O Offline
                                      opengpu
                                      wrote on 19 Jun 2019, 07:51 last edited by
                                      #35

                                      @raven-worx said in is there anyway to Send Email to someone in Qt?:

                                      does

                                      seems not. i put all of this in another thread. so better. but the time of this func is still slow. the time is mainly cost on connectToHost, login, sendMail. and u can easily test it.

                                      R 1 Reply Last reply 19 Jun 2019, 09:05
                                      0
                                      • O opengpu
                                        19 Jun 2019, 07:51

                                        @raven-worx said in is there anyway to Send Email to someone in Qt?:

                                        does

                                        seems not. i put all of this in another thread. so better. but the time of this func is still slow. the time is mainly cost on connectToHost, login, sendMail. and u can easily test it.

                                        R Offline
                                        R Offline
                                        raven-worx
                                        Moderators
                                        wrote on 19 Jun 2019, 09:05 last edited by raven-worx
                                        #36

                                        @opengpu said in is there anyway to Send Email to someone in Qt?:

                                        seems not. i put all of this in another thread. so better. but the time of this func is still slow. the time is mainly cost on connectToHost, login, sendMail. and u can easily test it.

                                        well it doesn't matter if you move it to another thread if you still create a new instance everytime you send an email.

                                        Also where does the SmtpClient class come from?

                                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                        If you have a question please use the forum so others can benefit from the solution in the future

                                        1 Reply Last reply
                                        0
                                        • R Offline
                                          R Offline
                                          Robert Hairgrove
                                          wrote on 16 Apr 2020, 08:58 last edited by
                                          #37

                                          Since no one has mentioned it, you can use QDesktopServices::openUrl() with a URL like "mailto:anybody@anywhere.com" which will open the default email client as a new message to that address. However, the user must fill in the subject and message body as well as adding any additional CC or BCC addresses, etc.

                                          But this might be enough if it is all you need, and extremely simple to use.

                                          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