I have a "simple" thread class that tries to send messages to an SMTP Server on our LAN. The Transport.connect method connects to the specified host and port successfully (which is not localhost). However, when Transport.send is called using the same Transport object a SendFailed Exception is thrown with the error "Could not connect to SMTP host: localhost, port: 25". I have no idea as to why it is trying to connect to localhost as nothing updates the Transport object between creation and the calling of the Send method (this is shown in the code below).
The constructor contains the following code where member variables are declared as follows:
private Session m_session = null;
private Properties m_props = new Properties();
private Transport m_transport = null;
// have tried Session.getDefaultInstance also
m_session = Session.getInstance(m_props);
The run method is as follows:
Transport transport = m_session.getTransport("smtp");
transport.connect(m_host, m_nPort, null, null);
// vecMessages is a Vector of MimeMessage objects
for (int i=0; i<vecMessages.size(); i++)
MimeMessage message = (MimeMessage) vecMessages.get(i);
if (null != message)
Any help would be greatly appreciated
The problem lies in the run method where I was creating the Transport object and then calling transport.send(...). The send method appears to use the defaults (host:localhost port:25). I changed the code to call transport.sendMessage (...) and this worked. sendMessage obviously uses the settings that were used to create the Transport object.
Hope this helps someone else.