PDA

View Full Version : Problem using gmail SMTP to send E-mail from application



Tottish
1st March 2011, 18:34
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/sending-e-mail-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:


{
qDebug() << "initializing Emailing...";


MailSender test("smtp.googlemail.com", "myname@gmail.com", QStringList("kristofer.johansson@tkoprototyping.com"), "ett", "två");
test.setSubject("Test2"),
test.setBody("Ångström");

test.setLogin("myname@gmail.com", "password");
test.setSsl(true);
test.setPort(465);

test.setPriority(MailSender::high);
if(test.send()) {
qDebug() << "mail sent";
}
else {
qDebug() << "failed to send mail";
qDebug() << test.lastError() << test.lastCmd() << test.lastResponse();
}

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

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

/Tottish

wysota
1st March 2011, 22:57
gmail uses a different port for smtp - 587.

squidge
1st March 2011, 23:41
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.

Tottish
2nd March 2011, 00:30
Acording to this:
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
you should be able to connect on 465 for SSL, right?

/Tottish

squidge
2nd March 2011, 08:58
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)

Tottish
2nd March 2011, 12:03
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:


5 3.008818 192.168.0.2 213.248.100.54 DNS Standard query A smtp.gmail.com
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

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:


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
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
9 3.346322 192.168.0.2 209.85.143.109 TCP 49740 > urd [ACK] Seq=1 Ack=1 Win=65800 Len=0

And then 30 seconds later when the function times out we've got this (from the same TCP-stream):


112 33.346640 192.168.0.2 209.85.143.109 TCP 49740 > urd [FIN, ACK] Seq=1 Ack=1 Win=65800 Len=0
113 33.479094 209.85.143.109 192.168.0.2 TCP urd > 49740 [ACK] Seq=1 Ack=2 Win=5760 Len=0
114 33.506080 209.85.143.109 192.168.0.2 TCP urd > 49740 [FIN, ACK] Seq=1 Ack=2 Win=5760 Len=0
115 33.506113 192.168.0.2 209.85.143.109 TCP 49740 > urd [ACK] Seq=2 Ack=2 Win=65800 Len=0


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

wysota
2nd March 2011, 12:39
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.

Tottish
2nd March 2011, 12:42
Thanks wysota. I'm sending you a PM about it.

wysota
2nd March 2011, 12:52
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.

Tottish
2nd March 2011, 12:58
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