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 sending email on Tomcat: javax.mail.NoSuchProviderException: smtp

user9291919Apr 13 2012 — edited May 4 2012
Hello,

I have an issue regarding sending emails within a Tomcat 5.0.28 server. The exception stacktrace is the following:
2012/04/13 04:27 27 [FATAL] ro.ss.asbuilt.business.methods.StarBaseMethod.sendNotification:301 - Error sending mailsmtp
javax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:750)
at javax.mail.Session.getTransport(Session.java:689)
at javax.mail.Session.getTransport(Session.java:632)
at javax.mail.Session.getTransport(Session.java:612)
at javax.mail.Session.getTransport(Session.java:667)
at javax.mail.Transport.send0(Transport.java:154)
at javax.mail.Transport.send(Transport.java:80)
at ro.ss.asbuilt.business.methods.StarBaseMethod.sendNotification(StarBaseMethod.java:295)

I'm using the mail_1.4.jar 1.4 and activation_1.1.jar libraries to send email.

Above the sendNotification method code:
...
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.port", "" + smtpPort);
Session sessionMail = Session.getInstance(props, null);

// Construct the message
Message msg = new MimeMessage(sessionMail);
try {
msg.setFrom(new InternetAddress(from));

msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setDataHandler(new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/html")));
// Send the message
if (msg != null) {
Transport.send(msg);
log.debug("Notificare trimisa cu succes la adresa: " + to.toString());
}
} catch (AddressException e) {
log.fatal("Error sending e-mail. Address not supported! " + e.getMessage(), e);
} catch (MessagingException e) {
log.fatal("Error sending mail" + e.getMessage(), e);
}
...

Thank you.

Best regards.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2012
Added on Apr 13 2012
2 comments
2,416 views