Results 1 to 10 of 10

Thread: Problem using gmail SMTP to send E-mail from application

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem using gmail SMTP to send E-mail from application

    Hi I'm trying to send Email from my qt-app.
    I'm using the MailSender class. Source code can be found here:
    http://forum.qtfr.org/viewtopic.php?id=7736
    The class is discussed here from post #9 and downwards:
    http://www.qtforum.org/article/26688...-with-qt4.html

    The example client code provided in the thread doesn't seem right (and doesn't work) so this is what I use:

    Qt Code:
    1. {
    2. qDebug() << "initializing Emailing...";
    3.  
    4.  
    5. MailSender test("smtp.googlemail.com", "myname@gmail.com", QStringList("kristofer.johansson@tkoprototyping.com"), "ett", "två");
    6. test.setSubject("Test2"),
    7. test.setBody("Ångström");
    8.  
    9. test.setLogin("myname@gmail.com", "password");
    10. test.setSsl(true);
    11. test.setPort(465);
    12.  
    13. test.setPriority(MailSender::high);
    14. if(test.send()) {
    15. qDebug() << "mail sent";
    16. }
    17. else {
    18. qDebug() << "failed to send mail";
    19. qDebug() << test.lastError() << test.lastCmd() << test.lastResponse();
    20. }
    To copy to clipboard, switch view to plain text mode 

    And this only results in a timeout error "Read timeout".

    Any ideas on why that might be or an alternate setting/solution?

    /Tottish

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using gmail SMTP to send E-mail from application

    gmail uses a different port for smtp - 587.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem using gmail SMTP to send E-mail from application

    I thought for Google, TLS was on 587 but SSL was still on 465.

    However, If Gmail (and any other server) abides by RFC 2476, then 587 should be the default submission (rather than relay) port. A lot of servers don't abide by this however.

  4. #4
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using gmail SMTP to send E-mail from application

    Acording to this:
    http://mail.google.com/support/bin/a...n&answer=13287
    you should be able to connect on 465 for SSL, right?

    /Tottish

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem using gmail SMTP to send E-mail from application

    Using a debugging utility such as Wireshark, what do you see? 'Read Timeout' sounds to me like a successfull connect, but a failed negotiation (ie, waiting for something that didn't appear in a suitable time frame)

  6. #6
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using gmail SMTP to send E-mail from application

    Well, I am completely new to Network analysis and have never used nor heard about Wireshark but I gave it a shot and perhaps you can tell me what the capture means.

    Sidenote: As you can see below I have changed the SMTP-server from smtp.googlemail.com to smtp.gmail.com. From what I've read both should work but they both produce the same error for me.

    When I trigger the function for sending the test email I immediately get these two packets:
    Qt Code:
    1. 5 3.008818 192.168.0.2 213.248.100.54 DNS Standard query A smtp.gmail.com
    2. 6 3.144012 213.248.100.54 192.168.0.2 DNS Standard query response CNAME gmail-smtp-msa.l.google.com A 209.85.143.109
    To copy to clipboard, switch view to plain text mode 
    I have no idea what this means but it seems that the smtp-server is sending me an IP address which appear in the capture below.
    Immediately following these two packets:
    Qt Code:
    1. 7 3.144764 192.168.0.2 209.85.143.109 TCP 49740 > urd [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=2 SACK_PERM=1
    2. 8 3.346257 209.85.143.109 192.168.0.2 TCP urd > 49740 [SYN, ACK] Seq=0 Ack=1 Win=5720 Len=0 MSS=1400 SACK_PERM=1 WS=6
    3. 9 3.346322 192.168.0.2 209.85.143.109 TCP 49740 > urd [ACK] Seq=1 Ack=1 Win=65800 Len=0
    To copy to clipboard, switch view to plain text mode 
    And then 30 seconds later when the function times out we've got this (from the same TCP-stream):
    Qt Code:
    1. 112 33.346640 192.168.0.2 209.85.143.109 TCP 49740 > urd [FIN, ACK] Seq=1 Ack=1 Win=65800 Len=0
    2. 113 33.479094 209.85.143.109 192.168.0.2 TCP urd > 49740 [ACK] Seq=1 Ack=2 Win=5760 Len=0
    3. 114 33.506080 209.85.143.109 192.168.0.2 TCP urd > 49740 [FIN, ACK] Seq=1 Ack=2 Win=5760 Len=0
    4. 115 33.506113 192.168.0.2 209.85.143.109 TCP 49740 > urd [ACK] Seq=2 Ack=2 Win=65800 Len=0
    To copy to clipboard, switch view to plain text mode 

    So, what do you make of this? It's a little hard to give you the right information since I'm new on this but just let me know if you need more/other information.

    Of course I would be extremely happy if someone had a working example of sending an email via gmails(or similar) smtp!

    Thank you very much!
    /Tottish

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using gmail SMTP to send E-mail from application

    Ok but this is only the connecting phase. Now you should send the ssl handshake. Otherwise after 30 seconds the server disconnects you (which you can see in the last block you posted).

    I do have a working example of using gmail but with QwwSmtpClient and not the class you are currently using.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using gmail SMTP to send E-mail from application

    Thanks wysota. I'm sending you a PM about it.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using gmail SMTP to send E-mail from application

    As for the class you are using - maybe you need to reorder the calls. To me it seems the class doesn't know it should be using ssl and waits for a regular handshake from the server which doesn't come because of lacking ssl negotiations.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    Tottish (2nd March 2011)

  11. #10
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using gmail SMTP to send E-mail from application

    OK, that might very well be the case but I don't really have the time to dig into that now. That is why I've decided to try it the wwWidgets way. See PM about example code request and licensing questions.

    Thanks!
    /Tottish

Similar Threads

  1. send mail from qt app problem
    By cutie.monkey in forum Qt Programming
    Replies: 12
    Last Post: 30th September 2010, 19:31
  2. Sending E-mail through Qt Application
    By baluk in forum Newbie
    Replies: 2
    Last Post: 11th September 2010, 18:01
  3. Why Yahoo & Gmail e-mail accounts are not accepted???
    By pat in forum Introduction to Qt
    Replies: 7
    Last Post: 20th May 2008, 17:16
  4. sending encrypted data via mail using smtp
    By vermarajeev in forum General Programming
    Replies: 20
    Last Post: 14th August 2007, 19:47
  5. Replies: 4
    Last Post: 17th June 2007, 10:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.