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 email by SMTP
Forum Updated to NodeBB v4.3 + New Features

Send email by SMTP

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 3 Posters 2.2k 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.
  • S Offline
    S Offline
    Saee1101
    wrote on last edited by
    #6

    @JonB I'm so sorry . I am confused about previous topic , thank you.
    I have gmail account and active security for access to send email .
    but I don't know get gmail password ?

    JonBJ 1 Reply Last reply
    0
    • S Saee1101

      @JonB I'm so sorry . I am confused about previous topic , thank you.
      I have gmail account and active security for access to send email .
      but I don't know get gmail password ?

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

      @Saee1101
      I don't know what you mean by "get gmail password"? To send email via Gmail SMTP you would need to send your gmail address and your password. I don't know what your password is, only you do. I am unsure whether if you are currently logged into gmail that would mean you do not need to send your username/password.

      V 1 Reply Last reply
      0
      • JonBJ JonB

        @Saee1101
        I don't know what you mean by "get gmail password"? To send email via Gmail SMTP you would need to send your gmail address and your password. I don't know what your password is, only you do. I am unsure whether if you are currently logged into gmail that would mean you do not need to send your username/password.

        V Offline
        V Offline
        Volker75
        wrote on last edited by
        #8

        @JonB No, you must NOT send your password. Watch my video. You need to create an extra password for your application. Using YOUR password doesn't work with google anymore.

        JonBJ 1 Reply Last reply
        1
        • V Volker75

          @JonB No, you must NOT send your password. Watch my video. You need to create an extra password for your application. Using YOUR password doesn't work with google anymore.

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

          @Volker75
          Hi. I am sure your information is useful, and OP should try your video. I am sorry but I do not watch any videos, if your was a text/code post I would happily read it. I do now vaguely remember about creating a password at Google side, Is this all to do with https://forum.qt.io/topic/134839/gmail-smtp-authentication/17 ?

          But in order to keep the functionality you have now, you need to enable 2FA and generate the "less secure app" credentials. That's the scope of the changes you face, if I read the situation correctly.

          If you want to guide this OP through what he has to do at the Qt side programatically at the client (in addition to set up at Gmail side), please do so!

          V 1 Reply Last reply
          0
          • JonBJ JonB

            @Volker75
            Hi. I am sure your information is useful, and OP should try your video. I am sorry but I do not watch any videos, if your was a text/code post I would happily read it. I do now vaguely remember about creating a password at Google side, Is this all to do with https://forum.qt.io/topic/134839/gmail-smtp-authentication/17 ?

            But in order to keep the functionality you have now, you need to enable 2FA and generate the "less secure app" credentials. That's the scope of the changes you face, if I read the situation correctly.

            If you want to guide this OP through what he has to do at the Qt side programatically at the client (in addition to set up at Gmail side), please do so!

            V Offline
            V Offline
            Volker75
            wrote on last edited by
            #10

            @JonB No problem. Yes, I am showing in the video how to create a new password and how to enable the 2FA. It is pretty hidden in the google settings. Difficult to explain with text only. You can see it in a video much better.
            In the c++ source it is easy. I also just use that simple-mail GitHub repository. The manual there is short and easy. Enabling the 2FA on google took me the most time.

            S 1 Reply Last reply
            1
            • V Volker75

              @JonB No problem. Yes, I am showing in the video how to create a new password and how to enable the 2FA. It is pretty hidden in the google settings. Difficult to explain with text only. You can see it in a video much better.
              In the c++ source it is easy. I also just use that simple-mail GitHub repository. The manual there is short and easy. Enabling the 2FA on google took me the most time.

              S Offline
              S Offline
              Saee1101
              wrote on last edited by Saee1101
              #11

              I did set password and 2FA for from@gmail.com

              Smtp *newmail=new Smtp("from@gmail.com","to@gmail.com","Test","Hi,I'm QtCreator");
              

              I'm sure enter password for "from@gmail.com" . but I don't know how do it ?

              V 1 Reply Last reply
              0
              • S Saee1101

                I did set password and 2FA for from@gmail.com

                Smtp *newmail=new Smtp("from@gmail.com","to@gmail.com","Test","Hi,I'm QtCreator");
                

                I'm sure enter password for "from@gmail.com" . but I don't know how do it ?

                V Offline
                V Offline
                Volker75
                wrote on last edited by Volker75
                #12

                @Saee1101 Just by

                newmail.setPassword(password);
                
                S 1 Reply Last reply
                0
                • V Volker75

                  @Saee1101 Just by

                  newmail.setPassword(password);
                  
                  S Offline
                  S Offline
                  Saee1101
                  wrote on last edited by
                  #13

                  @Volker75

                  #ifndef SMTP_H
                  #define SMTP_H
                  
                  #include <QTcpSocket>
                  #include <QString>
                  #include <QTextStream>
                  #include <QDebug>
                  #include <QMessageBox>
                  #include <QTextEdit>
                  
                  class Smtp : public QObject
                  {
                      Q_OBJECT
                  
                  
                  public:
                      Smtp( const QString &from, const QString &to,
                      const QString &subject, const QString &body );
                      ~Smtp();
                  QString base64Encode(const QString &plainText);
                  signals:
                      void status( const QString &);
                  
                  public slots:
                      void stateChanged();
                      void errorReceived();
                      void disconnected();
                      void connected();
                      void readyRead();
                  
                  private:
                      QString message;
                      QTextStream *t;
                      QTcpSocket *socket;
                      QString from;
                      QString rcpt;
                      QString response;
                       QTextEdit *output;
                      enum states{Rcpt,Mail,Data,Init,Body,Quit,Close};
                      int state;
                  
                  };
                  #endif
                  
                  

                  do you see setPassword ?!

                  V 1 Reply Last reply
                  0
                  • S Saee1101

                    @Volker75

                    #ifndef SMTP_H
                    #define SMTP_H
                    
                    #include <QTcpSocket>
                    #include <QString>
                    #include <QTextStream>
                    #include <QDebug>
                    #include <QMessageBox>
                    #include <QTextEdit>
                    
                    class Smtp : public QObject
                    {
                        Q_OBJECT
                    
                    
                    public:
                        Smtp( const QString &from, const QString &to,
                        const QString &subject, const QString &body );
                        ~Smtp();
                    QString base64Encode(const QString &plainText);
                    signals:
                        void status( const QString &);
                    
                    public slots:
                        void stateChanged();
                        void errorReceived();
                        void disconnected();
                        void connected();
                        void readyRead();
                    
                    private:
                        QString message;
                        QTextStream *t;
                        QTcpSocket *socket;
                        QString from;
                        QString rcpt;
                        QString response;
                         QTextEdit *output;
                        enum states{Rcpt,Mail,Data,Init,Body,Quit,Close};
                        int state;
                    
                    };
                    #endif
                    
                    

                    do you see setPassword ?!

                    V Offline
                    V Offline
                    Volker75
                    wrote on last edited by
                    #14

                    @Saee1101 Well, you should
                    #include "../../src/SmtpMime"

                    Did you saw the "demo" folder? Check out demo4.cpp and do it exactly like that.

                    S 1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Saee1101
                      wrote on last edited by
                      #15
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • V Volker75

                        @Saee1101 Well, you should
                        #include "../../src/SmtpMime"

                        Did you saw the "demo" folder? Check out demo4.cpp and do it exactly like that.

                        S Offline
                        S Offline
                        Saee1101
                        wrote on last edited by Saee1101
                        #16

                        @Volker75
                        I do Enable POP for all mail or Enable POP for mail that arrives from now on. Screenshot 1.png
                        Application Output :

                        host : "smtp.gmail.com"
                        port : 587
                        ssl : false
                        auth : false
                        user : "test.tivanex@gmail.com"
                        password : "nkjs **** **** ****"
                        [SmtpClient] State: ConnectingState
                        [Socket] State: QAbstractSocket::HostLookupState
                        [Socket] State: QAbstractSocket::ConnectingState
                        [Socket] State: QAbstractSocket::ConnectedState
                        [SmtpClient] State: ConnectedState
                        [Socket] IN:  "220 smtp.gmail.com ESMTP ti10-20020a170907c20a00b00a360ba43173sm370123ejc.99 - gsmtp\r\n"
                        [SmtpClient] State: _EHLO_State
                        [Socket] OUT: "EHLO localhost"
                        [Socket] IN:  "250-smtp.gmail.com at your service, [109.125.166.7]\r\n"
                        [Socket] IN:  "250-SIZE 35882577\r\n"
                        [Socket] IN:  "250-8BITMIME\r\n"
                        [Socket] IN:  "250-STARTTLS\r\n"
                        [Socket] IN:  "250-ENHANCEDSTATUSCODES\r\n"
                        [Socket] IN:  "250-PIPELINING\r\n"
                        [Socket] IN:  "250-CHUNKING\r\n"
                        [Socket] IN:  "250 SMTPUTF8\r\n"
                        [SmtpClient] State: _READY_Connected
                        [SmtpClient] State: ReadyState
                        [SmtpClient] State: MailSendingState
                        [SmtpClient] State: _MAIL_0_FROM
                        [Socket] OUT: "MAIL FROM:<test.tivanex@gmail.com>"
                        [Socket] IN:  "530-5.7.0 Must issue a STARTTLS command first. For more information, go to\r\n"
                        [Socket] IN:  "530-5.7.0  https://support.google.com/a/answer/3221692 and review RFC 3207\r\n"
                        [Socket] IN:  "530 5.7.0 specifications. ti10-20020a170907c20a00b00a360ba43173sm370123ejc.99 - gsmtp\r\n"
                        QWindowsWindow::setGeometry: Unable to set geometry 120x30+805+451 (frame: 136x69+797+420) on QWidgetWindow/"QErrorMessageClassWindow" on "\\.\DISPLAY1". Resulting geometry: 203x124+805+451 (frame: 219x163+797+420) margins: 8, 31, 8, 8 minimum size: 203x124 MINMAXINFO maxSize=0,0 maxpos=0,0 mintrack=219,163 maxtrack=0,0)
                        

                        Help me ,please
                        Help me ,please
                        Help me ,please

                        JonBJ 1 Reply Last reply
                        0
                        • S Saee1101

                          @Volker75
                          I do Enable POP for all mail or Enable POP for mail that arrives from now on. Screenshot 1.png
                          Application Output :

                          host : "smtp.gmail.com"
                          port : 587
                          ssl : false
                          auth : false
                          user : "test.tivanex@gmail.com"
                          password : "nkjs **** **** ****"
                          [SmtpClient] State: ConnectingState
                          [Socket] State: QAbstractSocket::HostLookupState
                          [Socket] State: QAbstractSocket::ConnectingState
                          [Socket] State: QAbstractSocket::ConnectedState
                          [SmtpClient] State: ConnectedState
                          [Socket] IN:  "220 smtp.gmail.com ESMTP ti10-20020a170907c20a00b00a360ba43173sm370123ejc.99 - gsmtp\r\n"
                          [SmtpClient] State: _EHLO_State
                          [Socket] OUT: "EHLO localhost"
                          [Socket] IN:  "250-smtp.gmail.com at your service, [109.125.166.7]\r\n"
                          [Socket] IN:  "250-SIZE 35882577\r\n"
                          [Socket] IN:  "250-8BITMIME\r\n"
                          [Socket] IN:  "250-STARTTLS\r\n"
                          [Socket] IN:  "250-ENHANCEDSTATUSCODES\r\n"
                          [Socket] IN:  "250-PIPELINING\r\n"
                          [Socket] IN:  "250-CHUNKING\r\n"
                          [Socket] IN:  "250 SMTPUTF8\r\n"
                          [SmtpClient] State: _READY_Connected
                          [SmtpClient] State: ReadyState
                          [SmtpClient] State: MailSendingState
                          [SmtpClient] State: _MAIL_0_FROM
                          [Socket] OUT: "MAIL FROM:<test.tivanex@gmail.com>"
                          [Socket] IN:  "530-5.7.0 Must issue a STARTTLS command first. For more information, go to\r\n"
                          [Socket] IN:  "530-5.7.0  https://support.google.com/a/answer/3221692 and review RFC 3207\r\n"
                          [Socket] IN:  "530 5.7.0 specifications. ti10-20020a170907c20a00b00a360ba43173sm370123ejc.99 - gsmtp\r\n"
                          QWindowsWindow::setGeometry: Unable to set geometry 120x30+805+451 (frame: 136x69+797+420) on QWidgetWindow/"QErrorMessageClassWindow" on "\\.\DISPLAY1". Resulting geometry: 203x124+805+451 (frame: 219x163+797+420) margins: 8, 31, 8, 8 minimum size: 203x124 MINMAXINFO maxSize=0,0 maxpos=0,0 mintrack=219,163 maxtrack=0,0)
                          

                          Help me ,please
                          Help me ,please
                          Help me ,please

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

                          @Saee1101 said in Send email by SMTP:

                          Help me ,please
                          Help me ,please
                          Help me ,please

                          ?

                          Have you acted on what the output error message tells you that you need to do, to send mail via this server?

                          S 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @Saee1101 said in Send email by SMTP:

                            Help me ,please
                            Help me ,please
                            Help me ,please

                            ?

                            Have you acted on what the output error message tells you that you need to do, to send mail via this server?

                            S Offline
                            S Offline
                            Saee1101
                            wrote on last edited by
                            #18

                            @JonB
                            NO , I don't know what to do , actually ?

                            JonBJ 1 Reply Last reply
                            0
                            • S Saee1101

                              @JonB
                              NO , I don't know what to do , actually ?

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

                              @Saee1101

                              530-5.7.0 Must issue a STARTTLS command first.

                              The server is telling you that you are trying to send a message unencrypted, but it requires encryption and won't just send in plain text. You can see from earlier that one of the commands it accepts is STARTTLS, and you need to issue that from your client.

                              I can't recall the details, you may wait for other responses. But I think after you send the initial EHLO greeting you then send a STARTTLS. And then I think you have to set up to use SSL socket. An example is at https://stackoverflow.com/questions/34215231/send-email-with-starttls, it's for Java but you get the idea. I'm sure you can get a better one by Googling for smtp starttls example, e.g. https://stackoverflow.com/questions/22957189/smtp-send-mail-with-qtcpsocket for Qt. If you looked at/are using https://github.com/bluetiger9/SmtpClient-for-Qt I see that mentions it has support for STARTTLS.

                              1 Reply Last reply
                              2

                              • Login

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