Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using gmail as SMTP server in Java web app is slow

I was wondering if anyone might be able to explain to me why it's taking nearly 30 seconds each time my Java web app sends an email using Gmail's SMTP server? See the following timestamps:

13/04/2010-22:24:27:281 DEBUG test.service.impl.SynchronousEmailService - Before sending mail. 13/04/2010-22:24:52:625 DEBUG test.service.impl.SynchronousEmailService - After sending mail.

I'm using spring's JavaMailSender class with the following settings:

email.host=smtp.gmail.com

[email protected] email.password=mypassword email.port=465 mail.smtp.auth.required=true

Note that the mail is getting sent and I'm receiving it fine, there's just this delay which is resulting in a slow experience for the application user.

If you know how I can diagnose the problem myself that would be good too :)

like image 539
JMM Avatar asked Apr 13 '10 12:04

JMM


2 Answers

It might be that gmail uses this delay to prevent spammers from using their SMTP server from the "outside": if the SMTP is called from the actual webmail client it would not use this delay. In order to test this, you could open a telnet session to port 25 and do a manual SMTP session (Search the web for SMTP HELO for examples)

like image 159
Tolli Avatar answered Sep 18 '22 21:09

Tolli


GMail uses SSL for connection. To validate SSL certificate properly certain time is needed. Exact time depends on complexity of the certificate chain and use and accessibility of CRLs and OCSP checking. It's very likely that Java checks OCSPs for the certificate(s) presented, and this can be slow.

Try running your application on different system (preferably in other subnet) to exclude influence of firewalls. Maybe some part of communication (either SMTP itself, or CRL retrieval or OCSP checking) is slowed down by the firewall.

like image 23
Eugene Mayevski 'Callback Avatar answered Sep 22 '22 21:09

Eugene Mayevski 'Callback