views:

103

answers:

1

I have a process (Message Driven Bean) that sends emails every time it gets a message. Emails per message are less than 10. I open 1 connection to my gmail account and send all emails over that one connection. Every now and then, I get an Exception on Transport.send()

    javax.mail.MessagingException: Can't send command to SMTP host; nested exception is:    
    java.net.SocketException: Connection closed by remote host at
    com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1878) at 
    com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1865) at 
    com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:973) at 
    javax.mail.Transport.send0(Transport.java:193) at 
    javax.mail.Transport.send(Transport.java:120) at 
....

Is gmail closing the connection because it thinks that it is spam? I know there is a limitation on number of cocurrent connections to gmail (10) but this seems different. Would using a connection pool help?

A: 

Either Gmail time out on your TCP/IP connection and decides to close it, or a firewall in between detects the connection to be idle and closes it.

Thorbjørn Ravn Andersen
I thought as much. But there is no idle time. The time between me opening the connection and sending the email is less than 30 secs. Moreover, this happens sporadically and in a lot of cases (not all), the email actually gets sent even though I get this error. We re considering using an SMTP relay service at this point.
ankimal