The main problem of "Can not connect to SMTP host: localhost, port: 25"
is that you've incorrectly configured your properties and JavaMail is using the
default host name "localhost".
Incorrect use of Session.getDefaultInstance can cause this problem.
Is your SMTP server on your local machine or not?
If not, then something has happened to the Properties that JavaMail is using
to find the host to connect to. Are you using the same Session object for all
messages? Did you create the Session object using the System Properties
object? If so, it looks like someone is removing a bunch of properties from
For read more information on Java Mail visit to :http://www.roseindia.net/javamail/