[2.0.1-java] Best way to send emails

221 views
Skip to first unread message

abhishek jain

unread,
Jul 23, 2012, 6:34:10 AM7/23/12
to play-fr...@googlegroups.com

Hi

Is there a good way to send emails, i have seen the following module, https://github.com/typesafehub/play-plugins/tree/master/mailer , but i am not happy with it, as it will need me read the template file and replace variables in template and then send email.

 

I will need a better solution which will not need me read the file via my code. Is it possible in play java 2.0.1 ?

 

Thanks

Abhishek jain

iammichiel

unread,
Jul 23, 2012, 11:03:07 AM7/23/12
to play-fr...@googlegroups.com
And what exactly do you need? Because I do not think there is any better solution then the one provided by Typesafe here. 

> It will need me read the template file.

What do you mean by that? 

abhishek

unread,
Jul 23, 2012, 12:31:20 PM7/23/12
to play-fr...@googlegroups.com


On Monday, July 23, 2012 8:33:07 PM UTC+5:30, iammichiel wrote:
And what exactly do you need? Because I do not think there is any better solution then the one provided by Typesafe here. 


I will prefer something like  for scala at link
https://github.com/taraxe/mail-plugin#readme
 
> It will need me read the template file.

What do you mean by that? 
Instead of reading the file from the filesystem , i will prefer like
mail.sendHtml(views.html.viewName.render(b) );

which don't work here for me.

thanks
abhishek

Ronald Haring

unread,
Jul 23, 2012, 2:26:35 PM7/23/12
to play-fr...@googlegroups.com
Did you try with:
mail.sendHtml(views.html.viewName.render(b).body())

The views.html.viewName.render(b).body() will return the html content of the page. That might work I think

Gr
Ronald

MG

unread,
Jul 23, 2012, 4:36:48 PM7/23/12
to play-fr...@googlegroups.com
Why not just use the Apache Commons Email directly?

-MG,
www.trustrecs.com

Michiel Missotten

unread,
Jul 24, 2012, 3:15:12 AM7/24/12
to play-fr...@googlegroups.com
The typesafe mailer plugin is nothing more than a scala adapter of the apache-commons library. All code under the hood is apache-commons.


> libraryDependencies += "org.apache.commons" % "commons-email" % "1.2", 

2012/7/23 MG <mohamme...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/HHY468TeI9IJ.

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.

Michiel Missotten

unread,
Jul 24, 2012, 3:17:28 AM7/24/12
to play-fr...@googlegroups.com
And as second answer, you can call toString directly after the render method. 


mail.send(
views.txt.helpers.mail.inscription().toString,
views.html.helpers.mail.inscription().toString
)


2012/7/24 Michiel Missotten <missotte...@gmail.com>

MG

unread,
Jul 28, 2012, 5:31:41 PM7/28/12
to play-fr...@googlegroups.com
I am not sure what is the benefit of using the scala adapter instead of using commons email directly. The commons email api is pretty straight forward and it took me almost the same time to learn how to use the TypseSafe Mailer as time to learn Commons Email API. So I am curious what is the benefit of the Typesafe scala adapter.

BTW, I am using the Commons Email from a Scala app.

-MG


On Tuesday, July 24, 2012 12:15:12 AM UTC-7, iammichiel wrote:
The typesafe mailer plugin is nothing more than a scala adapter of the apache-commons library. All code under the hood is apache-commons.


> libraryDependencies += "org.apache.commons" % "commons-email" % "1.2", 

2012/7/23 MG
Why not just use the Apache Commons Email directly?

-MG,
www.trustrecs.com

On Monday, July 23, 2012 3:34:10 AM UTC-7, abhishek wrote:

Hi

Is there a good way to send emails, i have seen the following module, https://github.com/typesafehub/play-plugins/tree/master/mailer , but i am not happy with it, as it will need me read the template file and replace variables in template and then send email.

 

I will need a better solution which will not need me read the file via my code. Is it possible in play java 2.0.1 ?

 

Thanks

Abhishek jain

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/HHY468TeI9IJ.

To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.

Ronald Haring

unread,
Jul 29, 2012, 9:51:40 AM7/29/12
to play-fr...@googlegroups.com
I think the benefit is that you can :
- use the same view that you use to show a page to a user, so you can mail that page as well
- since it uses the template, it will be type safe so no runtime exceptions when trying to mail

The only thing that I find missing is the default mockmail implementation of play 1. I wonder how I can emulate that?

Regards
Ronald

peter hausel

unread,
Jul 29, 2012, 2:54:08 PM7/29/12
to play-fr...@googlegroups.com

MG

unread,
Jul 29, 2012, 6:54:28 PM7/29/12
to play-fr...@googlegroups.com
I am not following your train of thought. What does a view have to do with email API?

Ronald Haring

unread,
Jul 30, 2012, 1:08:41 PM7/30/12
to play-fr...@googlegroups.com
ah great, thx Peter

@MG, well you will gain the type safety compilation of your message, so you can add parameters in your template which will be type safe. e.g.
Hello @user.firstname

glad you sent us an email concerning @subject. We will look into it right away

This can be a view for rendering on a html page but also for an email

Regards
Roald

MG

unread,
Jul 30, 2012, 6:36:38 PM7/30/12
to play-fr...@googlegroups.com
Ah, I see. Thanks for the elaboration. However, I think that rendering an email using a template is separate task; independent of the api used for sending it . One could use a view to render a custom email from a template and then pass the custom email to the commons email api.

Am I missing something?

-MG
Reply all
Reply to author
Forward
0 new messages