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