I am trying to send email using Gmail SMTP server from java (deployed in tomcat). When doing load testing if the number of request / sec to SMTP server grows more (>20) I get this exception
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:java.net.ConnectException: Connection timed out
Is there any limitations in access rate for Gmail SMTP server ? Should I introduce delay between each request ?
After some searching, introducing a delay between every email getting sent is the way to go if you want to keep using the SMTP servers from Google. However, from what I read, a significant delay is required for these SMTP servers in order for them not to forcibly close your connection and actively drop new connections (by significant delay, I mean delays of more than 60 seconds). Load testing is out of the question this way: modern computers should be able to process sending an email within 60 seconds without any problems.
Bottom line: don't use Gmail SMTP for load testing. I would recommend setting up your own SMTP server which you can use, or maybe (temporarily) get an account at a professional mailing service. Keep in mind though, that if you host your own SMTP server, there is a possibility that your software performs the way it should, but that the SMTP server can have spam protection (by default).