sending email in GWT project through RPC call

198 views
Skip to first unread message

danit ba

unread,
May 6, 2012, 2:45:06 AM5/6/12
to Google Web Toolkit
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();
}

Rob

unread,
May 10, 2012, 9:51:32 PM5/10/12
to Google Web Toolkit
Hi,

What do your web.xml and context.xml look like?

-> web.xml:

...

<context-param>
<param-name>MAIL-NAME</param-name>
<param-value>mail/GmailSmtpServer</param-value>
<description>The name of the mail Session used by sample
application.</description>
</context-param>

->

-> context.xml:

<Resource name="mail/GmailSmtpServer"
auth="Container"
type="javax.mail.Session"
mail.transport.protocol="smtp"
mail.smtp.host="smtp.gmail.com"
mail.smtp.port="465"
mail.smtp.auth="true"
mail.smtp.user="user...@gmail.com"
password="password"
mail.smtp.starttls.enable="true"

mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
mail.debug="true" />

->

Are you running hosted mode (no JNDI support ?) or have you deployed
the app to Tomcat and placed the jars in \lib (activation and mail)?

Cheers
Rob

http://code.google.com/p/gwt-cx/


On May 6, 4:45 pm, danit ba <dani...@gmail.com> wrote:
> 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 = "maildest...@gmail.com";

chrischris

unread,
Dec 23, 2013, 5:13:41 AM12/23/13
to google-we...@googlegroups.com
i have changed both web.xml, and context.xml

tried on tomcat and with google app engine,
no change, same excep

but may be i forgot a jar in lib ?

and for "mail.smtp.port" we give number we want or almost ?

chrischris

unread,
Dec 23, 2013, 5:57:17 AM12/23/13
to google-we...@googlegroups.com
adding javamail-1.4.7\lib jars in webing/lib

i got a different exception :
Exception reading response (java.net.SocketException: Socket operation timed out: The API call remote_socket.Receive() took too long to respond and was cancelled.)



Le dimanche 6 mai 2012 08:45:06 UTC+2, danit ba a écrit :
Reply all
Reply to author
Forward
0 new messages