Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Javamail ignoring mail.smtp.host?

843834Sep 20 2007 — edited Sep 27 2007
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 25 2007
Added on Sep 20 2007
7 comments
652 views