Javamail ignoring mail.smtp.host?
843834Sep 20 2007 — edited Sep 27 2007Hi all,
I have some code that looks like this (OK, this is oversimplified):
private void sendMessage(SMTPMessage message, String username, String domain) throws MessagingException
{
bq. String mxHost = getMXHostnames(domain)[0]; \\ Properties sessionProperties = new Properties(); \\ sessionProperties.put("mail.smtp.host", mxHost ); // This line is important! \\ Session session = Session.getInstance(sessionProperties); \\ URLName targetUrl = new URLName("SMTP", mxHost, 25, null, null, null); \\ SMTPTransport transport = new SMTPTransport(session, targetUrl); Address[] addr = new Address[]() {new InternetAddress(username \\ + '@' + domain)}; \\ transport.send(message, addrArray);
}
username and domain are variables containing a target address, and getMXHostnames() is a function returning an array of MX host names, sorted in order of preference, for a supplied domain name (I can verify that this works, or at least that it generates an array of very plausible-looking domain names, none of which is "localhost".
When I run this code, however, I get:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25
Where is that "localhost" coming from? I specified a value for mail.smtp.host, and it's not localhost! (An example is "mx1.balanced.swarthy.mail.dreamhost.com", for webmail hosted by DreamHost.)
Any help would be much appreciated.
Thanks much,
Avrom