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!

Connection lost when sending email from iSeries machine w/ JavaMail API?

843830Mar 8 2006 — edited Mar 22 2006
Hello all,

I have a never-ending process (RPGLE) running on the iSeries machine that frequently needs to send an email. In an attempt to improve performance, I connect to the SMTP server as soon as this process starts. Then, each time an email must be sent, I construct the message and send it. This seems to work, but occasionally (no particular pattern) something goes wrong that causes a javax.mail.MessagingException to be thrown. When this occurs, the process continues to retry the send until it works again... it always ends up working again after 4 minutes or less. However, I'm concerned about the fact that it gets this exception. Any suggestions or ideas would be greatly appreciated. Thanks! Jesse

Here are some code snippits:

~~~The RPGLE process first calls a method to setup the SMTP server and connect:
String hostName = "email.hostname";
String hostType = "email.hosttype";

// Get system properties
Properties systemProperty = System.getProperties();

// Setup mail server
systemProperty.put(hostType, hostName);
systemProperty.put("mail.smtp.connectiontimeout", "30000");
systemProperty.put("mail.smtp.timeout", "30000");

// Get session
session = Session.getDefaultInstance(systemProperty, null);

// Connect to the smtp server.
transport = session.getTransport("smtp");
transport.connect();


~~~ Then, when needed, the RPGLE process continues to call a method to send email. It is in here that the MessagingException is thrown.

if (!transport.isConnected())
transport.connect();

message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));

message.setSubject(subject);
message.setContent(text,"text/html");
message.setHeader("X-Mailer", "HtmlMail");
message.saveChanges();
transport.sendMessage(message, message.getRecipients (Message.RecipientType.TO));
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2006
Added on Mar 8 2006
7 comments
606 views