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 e-mail using Qt
Forum Updated to NodeBB v4.3 + New Features

Send e-mail using Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 5.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.
  • ODБOïO ODБOï

    Hello,
    Im trying to send an email to my gmail adress.

    i saw this thread : https://forum.qt.io/topic/70601/how-to-send-email-using-qt-5-5-1/10

    and i have decided to test this implementation : https://github.com/xcoder123/SimpleSmtp_SSL_QT5

    I compile and run the application but when i fill the form and click 'send' my app is not able to connect to smtp.gmail.com : 465

    stateChanged QAbstractSocket::HostLookupState
    stateChanged QAbstractSocket::ConnectingState
    stateChanged QAbstractSocket::UnconnectedState
    "Socket operation timed out"

    I don't realy know how to do now to make this work. Can someone help please ?
    Thank you

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

    @LeLev
    For smtp.gmail.com, you need to use Port 587. Are you doing that?

    Then after the connection you should use some equivalent of (this is using a Python library, but you get the gist):

                # upgrades the insecure server connection to a secure TLS method
                if settings.use_tls:
                    server.starttls()
    
                # identifies the the user to the SMTP server
                # note: .ehlo() is used NOT .helo(), .helo() is old and insecure
                server.ehlo()
    
                # user login credentials are passed to server
                server.login(settings.smtp_user, settings.smtp_password)
    
    1 Reply Last reply
    2
    • J.HilkJ J.Hilk

      @LeLev
      3 things come to my mind you can check,

      • is ssl support activated ? QSslSocket::supportsSsl()
      • are you behind a local proxy?
      • have you enabled the the less secure ssl handshake, a 4 year old repo is bound to use, in your gmail account?
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #4

      @J.Hilk, @JonB THX.

      is ssl support activated ? QSslSocket::supportsSsl() : **YES**
      are you behind a local proxy? : **YES** (could you tell me what to do for this ?)
      have you enabled the the less secure ssl handshake, a 4 year old repo is bound to use, in your gmail account? : **YES**
      

      @JonB said in Send e-mail using Qt:

      For smtp.gmail.com, you need to use Port 587. Are you doing that?

      I tryed to use port 587

      JonBJ J.HilkJ 2 Replies Last reply
      0
      • ODБOïO ODБOï

        @J.Hilk, @JonB THX.

        is ssl support activated ? QSslSocket::supportsSsl() : **YES**
        are you behind a local proxy? : **YES** (could you tell me what to do for this ?)
        have you enabled the the less secure ssl handshake, a 4 year old repo is bound to use, in your gmail account? : **YES**
        

        @JonB said in Send e-mail using Qt:

        For smtp.gmail.com, you need to use Port 587. Are you doing that?

        I tryed to use port 587

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

        @LeLev
        Also, just to be clear (this may or may not yet affect the connection stage you are at): in GMail you have to enable a setting in your Gmail Preferences or whatever to say you want to allow SMTP, have you done that too?

        ODБOïO 1 Reply Last reply
        1
        • ODБOïO ODБOï

          @J.Hilk, @JonB THX.

          is ssl support activated ? QSslSocket::supportsSsl() : **YES**
          are you behind a local proxy? : **YES** (could you tell me what to do for this ?)
          have you enabled the the less secure ssl handshake, a 4 year old repo is bound to use, in your gmail account? : **YES**
          

          @JonB said in Send e-mail using Qt:

          For smtp.gmail.com, you need to use Port 587. Are you doing that?

          I tryed to use port 587

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

          @LeLev
          Sry, havn't much experience with that. You can take a look at QNetworkProxy, that in theory should provide you with everything you need.

          In the past I circumvented the issu by connecting via Mobilephone hotspot. The usecase was for me, more or less guaranteed, to be without a proxy so I did not investigate the issue further.


          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
          • JonBJ JonB

            @LeLev
            Also, just to be clear (this may or may not yet affect the connection stage you are at): in GMail you have to enable a setting in your Gmail Preferences or whatever to say you want to allow SMTP, have you done that too?

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #7

            @JonB
            on my gmail account i only allowed less secure apps "MyAccount" > "Sign-in & security" > "Connected apps & sites" > "Allow less secure apps". I cant see option to enable/disable SMTP

            JonBJ 1 Reply Last reply
            0
            • ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by
              #8

              @J-Hilk I just re-checked my proxy settings and i have this :
              Effective proxy settings
              Use DIRECT connections.
              Source: SYSTEM

              1 Reply Last reply
              0
              • ODБOïO ODБOï

                @JonB
                on my gmail account i only allowed less secure apps "MyAccount" > "Sign-in & security" > "Connected apps & sites" > "Allow less secure apps". I cant see option to enable/disable SMTP

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

                @LeLev said in Send e-mail using Qt:

                @JonB
                on my gmail account i only allowed less secure apps "MyAccount" > "Sign-in & security" > "Connected apps & sites" > "Allow less secure apps". I cant see option to enable/disable SMTP

                I think you have what is necessary, I thought there was something else but it does not appear so.

                ODБOïO 1 Reply Last reply
                0
                • JonBJ JonB

                  @LeLev said in Send e-mail using Qt:

                  @JonB
                  on my gmail account i only allowed less secure apps "MyAccount" > "Sign-in & security" > "Connected apps & sites" > "Allow less secure apps". I cant see option to enable/disable SMTP

                  I think you have what is necessary, I thought there was something else but it does not appear so.

                  ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by
                  #10

                  @JonB ok thx.

                  How could i investigate to know what is wrong ?
                  As i already said, the applications compiles and run correctly but when i try to send an email i have this.. :

                  stateChanged QAbstractSocket::HostLookupState
                  stateChanged QAbstractSocket::ConnectingState
                  stateChanged QAbstractSocket::UnconnectedState
                  "Socket operation timed out"

                  I tryed to see network communication with WireShark.
                  It looks like i have no response from server :

                  myIp to 64.233.167.108 TCP 66 49485 → 587 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1

                  myIp to 64.233.167.108 TCP 66 [TCP Retransmission] 49485 → 587 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1

                  myIp to 64.233.167.108 TCP 62 [TCP Retransmission] 49485 → 587 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1

                  myIp to 64.233.167.109 TCP 66 49486 → 587 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1 // i dont know why the Destination changes here ..
                  ....
                  Thx

                  JonBJ 1 Reply Last reply
                  0
                  • ODБOïO ODБOï

                    @JonB ok thx.

                    How could i investigate to know what is wrong ?
                    As i already said, the applications compiles and run correctly but when i try to send an email i have this.. :

                    stateChanged QAbstractSocket::HostLookupState
                    stateChanged QAbstractSocket::ConnectingState
                    stateChanged QAbstractSocket::UnconnectedState
                    "Socket operation timed out"

                    I tryed to see network communication with WireShark.
                    It looks like i have no response from server :

                    myIp to 64.233.167.108 TCP 66 49485 → 587 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1

                    myIp to 64.233.167.108 TCP 66 [TCP Retransmission] 49485 → 587 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1

                    myIp to 64.233.167.108 TCP 62 [TCP Retransmission] 49485 → 587 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1

                    myIp to 64.233.167.109 TCP 66 49486 → 587 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1 // i dont know why the Destination changes here ..
                    ....
                    Thx

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

                    @LeLev
                    I'm afraid this is a bit beyond me. But you could start by verifying you can ping there correctly. Here's mine:

                    jon@ubuntu:~$ ping smtp.gmail.com
                    PING gmail-smtp-msa.l.google.com (64.233.166.109) 56(84) bytes of data.
                    64 bytes from wm-in-f109.1e100.net (64.233.166.109): icmp_seq=1 ttl=42 time=13.5 ms
                    64 bytes from wm-in-f109.1e100.net (64.233.166.109): icmp_seq=2 ttl=42 time=12.9 ms
                    64 bytes from wm-in-f109.1e100.net (64.233.166.109): icmp_seq=3 ttl=42 time=13.3 ms
                    

                    All ...166.109 (slightly different from yours), and no retransmits...

                    ODБOïO 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @LeLev
                      I'm afraid this is a bit beyond me. But you could start by verifying you can ping there correctly. Here's mine:

                      jon@ubuntu:~$ ping smtp.gmail.com
                      PING gmail-smtp-msa.l.google.com (64.233.166.109) 56(84) bytes of data.
                      64 bytes from wm-in-f109.1e100.net (64.233.166.109): icmp_seq=1 ttl=42 time=13.5 ms
                      64 bytes from wm-in-f109.1e100.net (64.233.166.109): icmp_seq=2 ttl=42 time=12.9 ms
                      64 bytes from wm-in-f109.1e100.net (64.233.166.109): icmp_seq=3 ttl=42 time=13.3 ms
                      

                      All ...166.109 (slightly different from yours), and no retransmits...

                      ODБOïO Offline
                      ODБOïO Offline
                      ODБOï
                      wrote on last edited by
                      #12

                      @JonB I also did it, it looks ok.

                      I also tested this online client, and sended an e-mail without probleme : https://www.smtper.net/
                      So i'm missing something...
                      Ok still thx.

                      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