Hmtl email and GAE

237 views
Skip to first unread message

Fabrice Claeys

unread,
Mar 24, 2011, 4:33:07 PM3/24/11
to play-fr...@googlegroups.com
Hello,

I have a problem with sending email in HTML format from GAE with Play!.


Here the trace:
play.exceptions.MailException: Error while sending email
	at play.libs.Mail.sendMessage(Mail.java:193)
	at play.libs.Mail.send(Mail.java:62)
	at play.mvc.Mailer.send(Mailer.java:347)
	at mailers.AdminMailer.htmlTest(AdminMailer.java:27)
	at controllers.Admin.sendEmail(Admin.java:63)
	at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_$1.run(Method_.java:165)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.privilegedInvoke(Method_.java:163)
	at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke_(Method_.java:124)
	at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke(Method_.java:43)
	at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:413)
	at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:408)
	at play.mvc.ActionInvoker.invoke(ActionInvoker.java:182)
	at play.server.ServletWrapper$ServletInvocation.execute(ServletWrapper.java:476)
	at play.Invoker$Invocation.run(Invoker.java:187)
	at play.server.ServletWrapper$ServletInvocation.run(ServletWrapper.java:467)
	at play.Invoker.invokeInThread(Invoker.java:61)
	at play.server.ServletWrapper.service(ServletWrapper.java:117)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
	at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:97)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
	at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
	at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:238)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.Server.handle(Server.java:326)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
	at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
	at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)
	at com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:261)
	at com.google.apphosting.base.RuntimePb$EvaluationRuntime$2.handleRequest(RuntimePb.java:8440)
	at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:454)
	at com.google.net.rpc.impl.Server$RpcTask.runInContext(Server.java:572)
	at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:448)
	at com.google.tracing.TraceContext.runInContext(TraceContext.java:688)
	at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:326)
	at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:318)
	at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:446)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:636)
Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : null:25
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
	at org.apache.commons.mail.Email.send(Email.java:1267)
	at play.libs.Mail.sendMessage(Mail.java:191)
	... 51 more
Caused by: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Converting html body failed)
	at javax.mail.Transport.send(Transport.java:163)
	at javax.mail.Transport.send(Transport.java:48)
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
	... 53 more
Caused by: javax.mail.MessagingException: Converting html body failed
	at com.google.appengine.api.mail.stdimpl.GMTransport.sendMessage(GMTransport.java:211)
	at javax.mail.Transport.send(Transport.java:95)
	... 55 more

Nicolas Leroux

unread,
Mar 24, 2011, 4:38:15 PM3/24/11
to play-fr...@googlegroups.com
You cannot use play email library with GAE, this is a limitation from GAE. You have to use the email service from GAE:


Nicolas
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Nicolas Leroux

unread,
Mar 24, 2011, 4:42:01 PM3/24/11
to play-fr...@googlegroups.com
Hmm, actually I am not so sure about it anymore. It used to be different, I don't really know what is happening, I need to do more research.

Nicolas

Fabrice Claeys

unread,
Mar 24, 2011, 4:46:13 PM3/24/11
to play-fr...@googlegroups.com, Nicolas Leroux
Thank's Nicolas

Actually I can send email from play and gae with txt template but not with HTML template.

Fabrice Claeys

unread,
Mar 28, 2011, 3:48:45 AM3/28/11
to play-fr...@googlegroups.com, Nicolas Leroux
I solve my problem by overriding the Mailer.send() and don't use the commons-email lib but following the google documentation

Pascal Voitot Dev

unread,
Mar 28, 2011, 4:44:09 AM3/28/11
to play-fr...@googlegroups.com
In your opinion, would it possible to integrate that in the GAE plugin so that it overrides classical Play! email API following Google recommendations?

Pascal

On Mon, Mar 28, 2011 at 9:48 AM, Fabrice Claeys <claeys....@gmail.com> wrote:
I solve my problem by overriding the Mailer.send() and don't use the commons-email lib but following the google documentation
--

David Wursteisen

unread,
Mar 28, 2011, 5:06:47 AM3/28/11
to play-fr...@googlegroups.com
But commons-email is bassed on JavaMail API according to
http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java?revision=1031900&view=markup (line 1130)

So it "should" work with commons-email.

the problem for me, is in the GMTransport.java. It check if the mail to send a String instance, otherwise throw the Exception (I had to decompile it using JAD....). The things that I don't understand, is : if the message sent is not a String, what it is ? Obviously, and if I'm not mistaken, this problem doesn't not occur in local, so it's not so easy to debug :P



2011/3/28 Pascal Voitot Dev <pascal.v...@gmail.com>

Fabrice Claeys

unread,
Mar 28, 2011, 10:04:07 AM3/28/11
to play-fr...@googlegroups.com, David Wursteisen
Yes, the problem doesn't occur in local.

Fabrice Claeys

unread,
Apr 1, 2011, 4:42:48 AM4/1/11
to play-fr...@googlegroups.com
Hello Pascal,

I begin to be satisfied with my solution, but I have a problem in the management
of attachments.

Concerning the integration in the GAE module,  I do not know how to do
yet.


Fabrice

Am1t

unread,
Jun 14, 2012, 3:40:47 PM6/14/12
to play-fr...@googlegroups.com
Hi Fabrice,

Can you please share your code on how you send an HTML email on GAE?

Thanks
Amit

Am1t

unread,
Jun 15, 2012, 5:51:04 PM6/15/12
to play-fr...@googlegroups.com
Got it working by overriding the send method of the mailer and using this:


Properties props = new Properties();

Session emailSession = Session.getDefaultInstance(props, null);

Multipart mp = new MimeMultipart();

MimeBodyPart htmlPart = new MimeBodyPart();

htmlPart.setContent(bodyHtml, "text/html");

mp.addBodyPart(htmlPart);

msg.setContent(mp);

Transport.send(msg);


Cheers
Amit
Reply all
Reply to author
Forward
0 new messages