Monday, December 23, 2013

Re: sending email in GWT project through RPC call

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 :
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();
                 }

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment