SMTP Server Changing Unpredictably

I am experiencing weird behavior in my JavaMail program. At first, mail sending works fine through a remote mail server. After the program has been running for a while, though, it starts trying to send messages through localhost.

I am creating my session once as follows and use it and only it for all mail handling in my program:

Properties properties = System.getProperties();

properties.put("mail.smtp.host", smtpHost);

properties.put("mail.smtp.auth","true");

// Disable the TOP command. Otherwise, JavaMail will raise an

// exception in calls to folder.fetch() and message.getContent()

// when dealing with a qmail server and messages that begin with

// a dot. See

//http://forum.java.sun.com/thread.jspa?messageID=4395487?

// for details.

properties.put("mail.pop3.disabletop","true");

Authenticator authenticator =new FixedAuthenticator(userName, password);

Session session = Session.getInstance(properties, authenticator);

I create a message to send as follows:

MimeMessage mimeMessage =new MimeMessage(session);

toAddresses = InternetAddress.parse(to,false);

mimeMessage.setRecipients(Message.RecipientType.TO, toAddresses);

ccAddresses = InternetAddress.parse(cc,false);

mimeMessage.setRecipients(Message.RecipientType.CC, ccAddresses);

mimeMessage.setSubject(subject);

InternetAddress fromAddress =new InternetAddress(from);

mimeMessage.setFrom(fromAddress);

Address replyToAddresses[] ={new InternetAddress(replyTo)};

mimeMessage.setReplyTo(replyToAddresses);

DataHandler dataHandler = createDataHandler(inputStream, contentType);

mimeMessage.setDataHandler(dataHandler);

I send the message as follows:

Transport.send(mimeMessage);

I dug around in this forum's archives and found various references to multithreaded apps having this problem due to use of statics and system properties. I'm thinking I can fix the problem by getting an instance of the Transport class from the Session and sending the message through it instead of calling the static Transport.send() method. Sound right? Or do I also have to change the way I'm setting up the Properties object?

[2827 byte] By [rcauvina] at [2007-11-27 7:51:32]
# 1

Most likely some other part of your application is changing the

System Properties object and removing the properties you set.

You could check for that when you detect the failure to see if that's

the cause. If it is, you can create your own Properties object and

add your properties to it, ignoring the System Properties object.

bshannona at 2007-7-12 19:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Is there any reason to use the system's Properties object? Do I add the same properties to the Properties object if I create it, or do I need to fill in some additional fields that are set by default in the system's Properties object?
rcauvina at 2007-7-12 19:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

There's a few properties from the System Properties object that will

be used as fallbacks, but in those cases it will go directly to the

system properties if it doesn't find them in your Properties object.

(Mostly "user.name", I believe.)

The biggest reason to use the System Properties is that it gives you

a convenient way to set properties on the "java" command line when

you invoke your program.

bshannona at 2007-7-12 19:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...