I need some help with a JavaMail API problem.
I'm working on a J2EE app, which can be configured to send mails on certain events. There's a page where the user needs to specify the SMTP server and optionally the username and password if the SMTP server requires authentication. Now, the requirement is that when the user enters this information and clicks on Save, the system should validate whether the values entered are valid or not and display an error message in case of invalid data.
I created a standalone program first which works fine. However, when I put that code in the application, i get an exception.
Here's the standalone program:
Now, the method i'm using in my application is exactly the same as the go() method above except how the messages get displayed to the user.
But i'm always gettting MessagingException, even when I've entered the correct values for SMTP server, user and password.
Here's the error message i'm getting:
2009-12-17 16:41:16,112 DEBUG [com.inmedius.mentor.ui.browser.ServerBean] [admin - ServerConfigurationController]: javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
Could anyone please guide me regarding where the problem could be? I'm pretty inexperienced with JavaMail. I have gone through the JavaMail FAQ but didn't find anything that could help me in this case. If I missed something, please point it out. Thanks a lot.
Yes, I'm able to ping the server host. In fact, the standalone program that I've copied above, is able to connect to the server if the data entered is valid and throws the correct exceptions when invalid data is entered. However, when I copied the code from the go() method of the standalone program to a class in my application, things don't work anymore and I always get the same MessagingException when transport.connect() is called.
I'm using 2 SMTP servers for testing - one of them doesn't require authentication and the other one does. I tried connecting to the SMTP server which doesn't require authentication from my app using java.net.Socket and it worked. But the requirement is that the code should work for servers with authentication also. I don't know if that's possible using Socket.
Any help in solving the problem is appreciated, whether using JavaMail or not. Thanks.
I'm on leave now, so I'll get back to you with the stack trace when I'm back in office again. But just a thought - could this have something to do with multi-threading? Am I supposed to synchronize on something? Thanks a lot for your help, Narendra.
Sorry about not replying earlier but indeed, there's nothing wrong with the code above. The problem was elsewhere due to which the "mail.host" property was not getting set in my application code. Thanks for your time, Narendra!