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 = "
mym...@gmail.com";
final String password = "mypassword";
final String to = "
maild...@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();
}