wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes GWT RPC mail error:javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "GWT RPC mail error:javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp " Watch "GWT RPC mail error:javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp " New topic
Author

GWT RPC mail error:javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp

danit ba
Greenhorn

Joined: May 08, 2012
Posts: 4
Hi,

I am trying to send html mail in GWT project through RPC call .
the RPC method is invoked successfully, but when the code gets to the
following line:

Transport transport = mailSession.getTransport("smtp");

I get
javax.mail.NoSuchProviderException: Unable to locate provider for
protocol: smtp

i have download javamail 1.4.5 and added the jars to the buildpath
(including smtp.jar ) but nothing helps.

could you please advice ?

* see below full code:
try{
final String from = "mymail@gmail.com";
final String password = "mypassword";
final String to = "maildestiny@gmail.com";
final String body = "<body> bla bla </body>";

String host = "smtp.gmail.com";
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", password);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session mailSession = Session.getDefaultInstance(props,
null);
// mailSession.setDebug(true);
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("bla bla blu");
message.setFrom(new InternetAddress(from));
message.setContent(body, "text/html");
InternetAddress toAddress = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO,
toAddress);
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, from, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (MessagingException e) {
e.printStackTrace();
}
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Welcome to the Ranch.

Is the code executed on the client or server side?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
danit ba
Greenhorn

Joined: May 08, 2012
Posts: 4
its running on the server side
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

This is not really a GWT issue. I will move this topic to a more appropriate forum for you.
In the mean while check out http://www.coderanch.com/t/274207/java/java/Sending-Email-Java-mail-API
danit ba
Greenhorn

Joined: May 08, 2012
Posts: 4
I read on the internet that in order to use java mail jar i should disable google app engine mail.
I did it by removing in from the libraries in the java build path tab (I'm using eclipse), and from the google menu : I removed the V from "use google app engine" checkbox.

but I still see in the log :
DEBUG: loading new provider protocol=gm, className=com.google.appengine.api.mail.stdimpl.GMTransport, vendor=null, version=null
Starting Jetty on port 8888

maybe this is the reason for the exception? how come it looks on appengine class if I removed it from classpath?
danit ba
Greenhorn

Joined: May 08, 2012
Posts: 4
I found I still had the appengine jars in my war/WEB-INF/LIB.
I removed it and now I get following exception :
java.net.UnknownHostException: smtp.gmail.com
 
 
subject: GWT RPC mail error:javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp
 
Similar Threads
JSP Email
sending mail with JavaMail
creating website basic question
Java Mail Problem
E mail using JSP Error