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!

Error trying to send email -- IOException while sending message

843830Aug 31 2006 — edited Aug 31 2006
Email is successful when:
I run my application through JDeveloper
or
when I use a classpath, but if I try to execute app via a jar file, i get the following error message: IOException while sending message.

The jar file does include mail.jar and activation.jar.

Below is my email code:
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class JMAR_Mail {
private String sendTo;
private String sentFrom;
private String host;
private String messageSubject;
private String messageText;

private MimeMessage msg;

public JMAR_Mail() {}

public JMAR_Mail(String sendTo, String sentFrom, String _host) {
sendTo = _sendTo;
sentFrom = _sentFrom;
host = _host;
}

public void setEmailSubject(String _messageSubject) {
messageSubject = _messageSubject;
} // end setEmailSubject

public void setEmailText(String _text) {
messageText = _text;
}

public void sendEmail() throws MessagingException {
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);

Session session = Session.getInstance(props, null);
InternetAddress addr = new InternetAddress();

// parses comma separted list of email addresses
InternetAddress[] address = addr.parse(sendTo);

msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(sentFrom));
msg.setSubject(messageSubject);
msg.setText(messageText);

msg.setRecipients(Message.RecipientType.TO, address);
msg.setSentDate(new Date());

Transport.send(msg);

} // end sendEmail
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 28 2006
Added on Aug 31 2006
2 comments
555 views