Reputation: 997
I am experiencing an issue where JAVA mail (JavaMail version 1.5.3) throws a Not Connected exception when sending email messages and the email does get sent out. I have been encountering this since 4 weeks ago. The issue seems mostly related to hosted exchange servers. The exception is as follows:
java.lang.IllegalStateException: Not connected com.sun.mail.smtp.SMTPTransport.checkConnected(SMTPTransport.java:2355) com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1151) com.email.sender.EmailSenderThread.sendEmailMessages(EmailSenderThread.java:127) com.email.sender.EmailSenderThread.threadProcess(EmailSenderThread.java:59) com.email.util.PhaseThread.run(PhaseThread.java:40) java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) java.util.concurrent.FutureTask.run(FutureTask.java:266) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:748)
I am working on getting the debug logs for the exception, but I was just wondering how this can be prevented as well as if there was an update rolled out to Exchange, because the code was working perfectly for years.
Thanks in advance !!!
Upvotes: 0
Views: 1147
Reputation: 9816
I did get the same exception since I forgot to check this. After adding a check everything worked again:
if (!mailSession.getTransport().isConnected()) {
//...reconnection code
Transport newTransport = mailSession.getMailSession().getTransport();
newTransport.connect(...);
mailSession.setTransport(newTransport);
}
Upvotes: 0
Reputation: 29971
If you're "pooling" the Transport object so it can be reused, the server is probably dropping the connection due to inactivity.
As for why the message is still sent even when you get this exception, your application must be doing something to reconnect after getting the exception.
Upvotes: 1