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?

