[Play Framework 2.0][Java] Help for Email Stuff

338 views
Skip to first unread message

sameer verasiya

unread,
Jul 30, 2012, 12:28:36 AM7/30/12
to play-fr...@googlegroups.com
Hey Players..!!


I just want to know how we may setup sending and Receiving E-mails in Play Framework 2.0 from the scratch.. I am a noob and don't how it could be done.. Any help would be very much appreciated.. Thanks :)

Senthil Kumar R.G.

unread,
Jul 30, 2012, 12:44:54 AM7/30/12
to play-fr...@googlegroups.com
Hi Sameer

Please use this link for sending and receiving mails in play framework 2.0
You need a specialized plugin to be added in the application
Follow the step.

https://github.com/typesafehub/play-plugins/tree/master/mailer
 


On Mon, Jul 30, 2012 at 9:58 AM, sameer verasiya <sameer...@gmail.com> wrote:
Hey Players..!!


I just want to know how we may setup sending and Receiving E-mails in Play Framework 2.0 from the scratch.. I am a noob and don't how it could be done.. Any help would be very much appreciated.. Thanks :)

--
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/-/5fUsBC9rZZcJ.
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.

Sameer Verasiya

unread,
Jul 30, 2012, 2:28:01 AM7/30/12
to play-fr...@googlegroups.com
do I have to put MailerPlugin.scala and java file in my project??

as this https://github.com/typesafehub/play-plugins/tree/master/mailer imports

import com.typesafe.plugin.*;

??

Senthil Kumar R.G.

unread,
Jul 30, 2012, 2:43:18 AM7/30/12
to play-fr...@googlegroups.com
Hi

Let me tell the hierarchy of the project file

Yes u have to put in your project

Myproject -> project name
      > under myproject u will get conf folder plz create/write the content to file called  play.plugins and the line is 1500:com.typesafe.plugin.CommonsMailerPlugin
      > u will see a folder called project  there add the liine said the website .
      > change the settings in application.conf email settings so that u will send and receive the email.

restart play and check.

Sameer Verasiya

unread,
Jul 30, 2012, 2:49:04 AM7/30/12
to play-fr...@googlegroups.com
This isn't working actually as I did put configured Build.Scala ,
added play.plugins in my conf folder else copied MailerPlugin.scala
file and MailerApiJavaInterop.java and pasted in my new package named
com.typesafe.plugin

I am getting errors using methods like addRecipient, addFrom and
sendHtml .. Please can anyone help?

You may find the attachment of my project.. please help :)
mailWork.tar.gz

Sameer Verasiya

unread,
Jul 30, 2012, 3:01:32 AM7/30/12
to play-fr...@googlegroups.com
Would you please do the addition in the project which i have sent as
its not pretty clear to me where m i wrong as i have done everything

On Mon, Jul 30, 2012 at 11:49 AM, Sameer Verasiya

Senthil Kumar R.G.

unread,
Jul 30, 2012, 3:20:33 AM7/30/12
to play-fr...@googlegroups.com
Hi

Please check this sample java code which is working from my end
javaemp.zip

Senthil Kumar R.G.

unread,
Jul 30, 2012, 3:25:47 AM7/30/12
to play-fr...@googlegroups.com
Hi sameer

Note this : after adding plugin in your project while u run ur project u will get the mail plugin being extracted in your project

[info] Updating {file:/E:/Senthil/Scala/play-2.0.2/javaemp/}javaemp...
[info] Resolving org.hibernate.javax.persistence#hibernate-jpa-2.0-api;1.0.1.Fin

[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play-
plugins-mailer_2.9.1/2.0.2/play-plugins-mailer_2.9.1-2.0.2.jar ...
[info]  [SUCCESSFUL ] com.typesafe#play-plugins-mailer_2.9.1;2.0.2!play-plugins-
mailer_2.9.1.jar (2906ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play-
plugins-util_2.9.1/2.0.2/play-plugins-util_2.9.1-2.0.2.jar ...
[info]  [SUCCESSFUL ] com.typesafe#play-plugins-util_2.9.1;2.0.2!play-plugins-ut
il_2.9.1.jar (1859ms)
[info] Done updating.
--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on port 9002...

(Server started, use Ctrl+D to stop and go back to the console...)


On Mon, Jul 30, 2012 at 12:31 PM, Sameer Verasiya <sameer...@gmail.com> wrote:

Sameer Verasiya

unread,
Jul 30, 2012, 3:30:06 AM7/30/12
to play-fr...@googlegroups.com
Hey Senthil..!!

Thanks for the project file.. actually when i ran this project into
the play console by using play comman .. it is not resolving the
dependencies.. here is the issue

Getting org.scala-tools.sbt sbt_2.9.1 0.11.3 ...

:: problems summary ::
:::: WARNINGS
module not found: org.scala-tools.sbt#sbt_2.9.1;0.11.3

==== local: tried

/home/ssverasiya/Documents/Softwares/play-2.0/framework/../repository/local/org.scala-tools.sbt/sbt_2.9.1/0.11.3/ivys/ivy.xml

==== Maven2 Local: tried

file:///home/ssverasiya/.m2/repository/org/scala-tools/sbt/sbt_2.9.1/0.11.3/sbt_2.9.1-0.11.3.pom

==== typesafe-ivy-releases: tried

http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt_2.9.1/0.11.3/ivys/ivy.xml

==== Maven Central: tried

http://repo1.maven.org/maven2/org/scala-tools/sbt/sbt_2.9.1/0.11.3/sbt_2.9.1-0.11.3.pom

==== Scala-Tools Maven2 Repository: tried

http://scala-tools.org/repo-releases/org/scala-tools/sbt/sbt_2.9.1/0.11.3/sbt_2.9.1-0.11.3.pom

==== Scala-Tools Maven2 Snapshots Repository: tried

http://scala-tools.org/repo-snapshots/org/scala-tools/sbt/sbt_2.9.1/0.11.3/sbt_2.9.1-0.11.3.pom

::::::::::::::::::::::::::::::::::::::::::::::

:: UNRESOLVED DEPENDENCIES ::

::::::::::::::::::::::::::::::::::::::::::::::

:: org.scala-tools.sbt#sbt_2.9.1;0.11.3: not found

::::::::::::::::::::::::::::::::::::::::::::::



:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
unresolved dependency: org.scala-tools.sbt#sbt_2.9.1;0.11.3: not found
Error during sbt execution: Error retrieving required libraries
(see /home/ssverasiya/Documents/Softwares/play-2.0/framework/sbt/boot/update.log
for complete log)
Error: Could not retrieve sbt 0.11.3
ssverasiya@ssverasiya:~/Downloads/javaemp$ play run
Getting org.scala-tools.sbt sbt_2.9.1 0.11.3 ...

:: problems summary ::
:::: WARNINGS
module not found: org.scala-tools.sbt#sbt_2.9.1;0.11.3

==== local: tried

/home/ssverasiya/Documents/Softwares/play-2.0/framework/../repository/local/org.scala-tools.sbt/sbt_2.9.1/0.11.3/ivys/ivy.xml

==== Maven2 Local: tried

file:///home/ssverasiya/.m2/repository/org/scala-tools/sbt/sbt_2.9.1/0.11.3/sbt_2.9.1-0.11.3.pom

==== typesafe-ivy-releases: tried

http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt_2.9.1/0.11.3/ivys/ivy.xml

==== Maven Central: tried

http://repo1.maven.org/maven2/org/scala-tools/sbt/sbt_2.9.1/0.11.3/sbt_2.9.1-0.11.3.pom

==== Scala-Tools Maven2 Repository: tried

http://scala-tools.org/repo-releases/org/scala-tools/sbt/sbt_2.9.1/0.11.3/sbt_2.9.1-0.11.3.pom

==== Scala-Tools Maven2 Snapshots Repository: tried

http://scala-tools.org/repo-snapshots/org/scala-tools/sbt/sbt_2.9.1/0.11.3/sbt_2.9.1-0.11.3.pom

::::::::::::::::::::::::::::::::::::::::::::::

:: UNRESOLVED DEPENDENCIES ::

::::::::::::::::::::::::::::::::::::::::::::::

:: org.scala-tools.sbt#sbt_2.9.1;0.11.3: not found

::::::::::::::::::::::::::::::::::::::::::::::



:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
unresolved dependency: org.scala-tools.sbt#sbt_2.9.1;0.11.3: not found
Error during sbt execution: Error retrieving required libraries
(see /home/ssverasiya/Documents/Softwares/play-2.0/framework/sbt/boot/update.log
for complete log)
Error: Could not retrieve sbt 0.11.3


Is that cuz m using play 2.0?????

On Mon, Jul 30, 2012 at 12:20 PM, Senthil Kumar R.G.

Senthil Kumar R.G.

unread,
Jul 30, 2012, 3:39:23 AM7/30/12
to play-fr...@googlegroups.com

This error is because conflict of play version mismatch in my machine and urs.
Ok u do one thing, just create a new project inside the play folder and add the extra files that i have gave i.e in conf/play.plugins folder and build.scala ,application.scala i have added code to send email just see it.

Senthil Kumar R.G.

unread,
Jul 30, 2012, 3:40:03 AM7/30/12
to play-fr...@googlegroups.com
Which play version ur using. is that play 2.0 because i am using play 2.0

Sameer Verasiya

unread,
Jul 30, 2012, 3:51:47 AM7/30/12
to play-fr...@googlegroups.com
yes i m using play 2.0.. I m using linux as an operating system.. can
you just tht project file i sent u earlier .. n else i have also
figuerd out the build.properties file .. the project u sent had
build.properties in which the sbt version is bt.version=0.11.3 and i
have sbt.version=0.11.2


is that an issue?? and else it also not allowing me to eclipsify your
project plus am not able to import your project in eclipse as well

On Mon, Jul 30, 2012 at 12:40 PM, Senthil Kumar R.G.

Senthil Kumar R.G.

unread,
Jul 30, 2012, 4:25:59 AM7/30/12
to play-fr...@googlegroups.com
Hi
It worked for me i mean i tested ur code and it works the mistake u made is go to ur application.java file and change with this code

Note u have to add configuration in application.conf file also

package controllers;

import play.*;
import play.mvc.*;
import com.typesafe.plugin.*;

import views.html.*;

public class Application extends Controller {
 
  public static Result index() {
    MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
    mail.setSubject("mailer");
    mail.addRecipient("r.g.s...@agriya.in");
    mail.addFrom("Peter Hausel <nor...@email.com>");
    //sends html
    mail.sendHtml("<html>html</html>" );
    //sends text/text
    //mail.send( "text" );
    //sends both text and html
    //mail.send( "text", "<html>html</html>");
    return ok(index.render("Your new application is ready."));

Senthil Kumar R.G.

unread,
Jul 30, 2012, 4:26:47 AM7/30/12
to play-fr...@googlegroups.com
Can u tell me why u add com folder in mailWork\app ? plz remove it and check

Sameer Verasiya

unread,
Jul 30, 2012, 4:39:19 AM7/30/12
to play-fr...@googlegroups.com
hey

i have removed tht package from the app folder else copied the same code as u sent things r goin fine but i m haven an execution exception which is

[EmailException: Sending the email to the following server failed : localhost:25]
In /home/ssverasiya/Documents/rbehelperWork/mailWork/app/controllers/Application.java at line 19.

15    mail.setSubject("mailer");

16    mail.addRecipient("sameer...@gmail.com");

17    mail.addFrom("sameer...@gmail.com");

18    //sends html

19    mail.sendHtml("<html>html</html>" );

20    //sends text/text

21    //mail.send( "text" );

22    //sends both text and html

23    //mail.send( "text", "<html>html</html>");


the following properties are there in my application.conf file

smtp.host="smtp.gmail.com"
smtp.port="25"
smtp.ssl="yes"

Sameer Verasiya

unread,
Jul 30, 2012, 4:40:16 AM7/30/12
to play-fr...@googlegroups.com
my controller


  public static Result index() {
      
     
          MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
        mail.setSubject("mailer");
        mail.addRecipient("sameer...@gmail.com");
        mail.addFrom("sameer...@gmail.com");

Senthil Kumar R.G.

unread,
Jul 30, 2012, 5:28:41 AM7/30/12
to play-fr...@googlegroups.com
u check the gmail settings in google for sending mail

Sameer Verasiya

unread,
Jul 30, 2012, 5:32:34 AM7/30/12
to play-fr...@googlegroups.com

Atlast.. Done .. :) Email sent :) Thanks a lot Senthil for your support.. Owe u ..!!

Senthil Kumar R.G.

unread,
Jul 30, 2012, 5:36:31 AM7/30/12
to play-fr...@googlegroups.com
what solution u found for email send settings in gmail.

Sameer Verasiya

unread,
Jul 30, 2012, 5:38:01 AM7/30/12
to play-fr...@googlegroups.com
There wasn't any issue man .. actually i dint put two properties in my Application.conf file and it was the username and password..

Senthil Kumar R.G.

unread,
Jul 30, 2012, 5:39:14 AM7/30/12
to play-fr...@googlegroups.com
Oh k fine have great day.

Sameer Verasiya

unread,
Jul 30, 2012, 5:41:27 AM7/30/12
to play-fr...@googlegroups.com
Thanks a lot buddy.. Thank you

Senthil Kumar R.G.

unread,
Jul 30, 2012, 6:17:34 AM7/30/12
to play-fr...@googlegroups.com
Hi can u help me from this. i m using scala not java with play 2.0

1.  What is the alternative for request.action i.e i need the action and method name of current page.

2. How to change the config variable
    In play 1.0 i used setConfig but in play 2.X there is no such property in configuration.

3. How to store cookie values is there any way other than withCookies in redirect(routes.user.create)

4. Whether flashing will work only in redirect

Sameer Verasiya

unread,
Jul 30, 2012, 6:34:33 AM7/30/12
to play-fr...@googlegroups.com
dude I m a complete noob in play framework 2.0 ..,.. actually i started working with play about 2 months ago n tht too with play 2.0 and i really dont know scala tht much as i am a java developer..

 i wanted to know is there any example of sending attachments with the email?
Reply all
Reply to author
Forward
0 new messages