• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Tomcat throws " javax.mail.NoSuchProviderException: No provider for smtp"

F

flupke

Guest
Hello,

customer tries to send email over Tomcat, no luck up to now, Tomcat throws an exception 'no provider for SMTP'. "Transport transport = mailSession.getTransport("smtp");" causes the exceptions. It is an internal Tomcat issues (path, authorization to use smtp...) but not to Qmail.

Any Tomcat guru with advises?

Here the code and exception

implementation of sendMail method:
>
> ppublic static boolean sendMail( String mailSmtp, String mailFrom,
> String mailTo,
> String mailSubject, String mailMessage ) throws Exception
> {
> try {
> String host = "DOMAIN";
> String user = "usrer";
> String pass = "xxxx";
> boolean sessionDebug = true;
>
> Properties properties = new Properties();
> properties.put( "mail.smtp.host", mailSmtp );
> properties.put("mail.transport.protocol", "smtp");
> properties.put( "mail.from", mailFrom );
> properties.put("mail.smtp.auth", "true");
>
> Session mailSession = Session.getInstance( properties, null );
> mailSession.setDebug(sessionDebug);
>
> InternetAddress[] mailAddress = { new InternetAddress( mailTo ) };
> SMTPMessage message = new SMTPMessage( mailSession );
> message.setRecipients( Message.RecipientType.TO, mailAddress );
> message.setFrom( new InternetAddress( mailFrom ) );
> message.setSubject( mailSubject );
> message.setContent( mailMessage, "text/html" );
> message.setSentDate( new Date() );
>
> Transport transport = mailSession.getTransport("smtp");
> transport.addConnectionListener( new ConnectionHandler() );
> transport.addTransportListener( new TransportHandler() );
> transport.connect(host, user, pass);
> transport.sendMessage( message, mailAddress );
> transport.close();
> } catch ( Exception ex ) {
> System.out.println("SendMail Exception " + ex.getMessage());
> return false;
> }
>
> return true;
> }
>
>
>
> --------- exception -------
>
> The statement " Transport transport =
> mailSession.getTransport("smtp");" causes the excpetion:
>
> javax.mail.NoSuchProviderException: No provider for smtp
> at javax.mail.Session.getProvider(Session.java:289)
> at javax.mail.Session.getStore(Session.java:363)
> at SimpleClient.main(SimpleClient.java:118)
 
Hi,
I am having a similar problem for a customer of mine.
I was wondering if you were able to solve the problem?
 
Geneo,
We use NGASI AppServer Manager for our Java Hosting.
One of the features is configuring the Mail object for applications
to access. So you don't have to become a java export.
Their website is http://www.ngasi.com. It works with Plesk,
which we use for general web site management.
 
Yeah. Thanks for the info. ngasi was exactly the solution I was looking for!
Wow. It also has the ability to configure each customer's application datasource as well virtual hosting.

Thanks again for the link.
 
Hi everyone,I'm having the same problem

javax.mail.NoSuchProviderException: smtp
javax.mail.Session.getService(Session.java:764)
javax.mail.Session.getTransport(Session.java:689)
javax.mail.Session.getTransport(Session.java:632)
javax.mail.Session.getTransport(Session.java:612)
org.apache.jsp.DemoSendMail_jsp._jspService(DemoSendMail_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.vtr.globarena.URLCheckFilter.doFilter(URLCheckFilter.java:175)

I've added activation.jar and mail.jar and restart tomcat but it is still throwing the same exception our server is configured in linux.
need help plz it's very urgent..................

My code is :-

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!--<%@page import="java.security.Security"%>
<%@page import="java.util.Properties"%>-->
<%@page import="javax.mail.Message"%>
<%@page import="javax.mail.MessagingException"%>
<%@page import="javax.mail.PasswordAuthentication"%>
<%@page import="javax.mail.Session"%>
<%@page import="javax.mail.Transport"%>
<%@page import="javax.mail.internet.InternetAddress"%>
<%@page import="javax.mail.internet.MimeMessage"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String host="", user="", pass="";
//host = "smtp.yahoo.com"; //"smtp.gmail.com";
//user = "[email protected]"; //"[email protected]"
//pass = "XXXXXX"; //"Your password"
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
String to = "[email protected]"; // out going email id
String from = "[email protected]"; //Email id of the recipient
String subject = "subject";
String messageText = "This is a test Email sent by jsp page";
boolean sessionDebug = true;
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol.", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setContent(messageText, "text/html"); // use setText if you want to send text
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, pass);
try {
transport.sendMessage(msg, msg.getAllRecipients());
out.println("Email sent");
//WasEmailSent = true; // assume it was sent
}
catch (Exception err) {
//WasEmailSent = false; // assume it's a fail
}
transport.close();
%>

</body>
</html>
 
I had the same problem too and dug around for a few mins. Turns out that my OS (CentOS) installs the GNU version of the Javamail library which isn't set up right and you need to install the sun version. Doing this solved the problem.
you can follow the instructions here if you need help on how to do that.
 
I'm new to the linux server configuration

But i've installed the latest library of mail.jar and activation.jar from sun website and installed it with FTP server.
Need help
 
install it manually as per the instructions onthat site as I doubt the ftp server updated the symlinks.
Start reading from the paragraph after the 3rd code box. (The light yellow boxes showing command line instructions)
 
Hello sir every one i to facing the problem with the javax.mail.NoSuchProviderExcepti

sir please resolve me from this problem that iam facing with the exception javax.mail.NoSuchProviderException:smtp
.....please help me urgent
javax.mail.NoSuchProviderException: smtp
javax.mail.Session.getService(Session.java:768)
at javax.mail.Session.getTransport(Session.java:708)
at javax.mail.Session.getTransport(Session.java:651)
at javax.mail.Session.getTransport(Session.java:631)
at javax.mail.Session.getTransport(Session.java:686)
at javax.mail.Transport.send0(Transport.java:166)
at javax.mail.Transport.send(Transport.java:98)
at com.phrdomain.SendHTMLEmail.main(SendHTMLEmail.java:72)
 
Last edited:
javax.mail.NoSuchProviderException:smtp

All you have to do is ....Go to your tomcat lib directory and remove the existing default java mail jar.

/usr/share/tomcat5/common/lib/
[javamail].jar -> /usr/share/java/javamail.jar

rm [javamail].jar


restart your tomcat server.
/etc/rc.d/init.d/tomcat5 restart

Try now. It should work.
Make sure your application WAR file has javax.mail.jar
 
It also has the ability to configure each customer's application datasource as well virtual hosting.

Thanks again for the link.
 
Back
Top