Reputation: 3
I would like send e-mail with play farmework. I configure my application.conf
# Testing. Set up a custom configuration for test mode
# ~~~~~
#%test.module.cobertura=${play.path}/modules/cobertura
%test.application.mode=dev
%test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
%test.jpa.ddl=create
%test.mail.smtp=mock
#Testing use smtp gmail
#~~~~~~~
mail.debug=true
mail.smtp.host=smtp.gmail.com
[email protected]
mail.smtp.pass=mypassword
mail.smtp.channel=ssl
I create a new template email in /views/Mails/welcome.html and welcome.txt And i write static method will be an e-mail sender
package notifiers;
import play.*;
import play.libs.Mail;
import play.mvc.*;
import java.util.*;
import javax.mail.Folder;
public class Mails extends Mailer {
public static void welcome(){
setSubject("Test Send Mail");
addRecipient("[email protected]");
setFrom("Me <[email protected]>");
send();
}
}
I have in my output console message
begin function welcom()
10:30:36,857 INFO ~ From Mock Mailer
New email received by
From: [email protected]
ReplyTo: [email protected]
To: "[email protected]" <[email protected]>
Subject: Test Send Mail
text/plain; charset=UTF-8: hello world
text/html; charset=UTF-8: <html>
<body>
<p>Hello world</p>
</body>
</html>
finish function welcom()
finally I do not receive mail. Pls help.Thank you.
Upvotes: 0
Views: 511
Reputation: 18446
You have the line
mail.smtp=mock
somewhere in your application.conf
. This makes Play use a mock mailer instead of mailing via an SMTP server. The default behaviour is to have the mock mailer in DEV mode and an SMTP mailer in PROD mode. You can change this behaviour by commenting out the mentioned line in your config.
Also please note that you shouldn't be using Play 1.2.5 anymore. The currently newest version of the 1.X branch is 1.2.7. Your version, 1.2.5, contains a session injection vulnerability.
Upvotes: 2