Use spring JavaMailSender
to send email, sometimes there are below exception
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: mail.foo.com, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: mail.foo.com, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:432) ~[spring-context-support-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345) ~[spring-context-support-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340) ~[spring-context-support-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]
At first I thought maybe the default timeout is not long enough, and I could set a longer value to avoid the exception. e.g.
<prop key="mail.smtp.timeout">10000</prop>
but when I read the document I find the defalt timeout value is infinite
please see: https://javamail.java.net/nonav/docs/api/com/sun/mail/smtp/package-summary.html
So if it is infinite it should be blocked forever, why could have ConnectException
?