Text/plain e-MailIf no HTML template is defined, then a text/plain e-mail is sent using the text template.
The send method call would render the app/views/mails/welcome.txt template as the e-mail message body.
Welcome ${user.name},...
The template for the LostPassword method could:
App/views/mails/lostpassword.txt
Hello ${user.name}, Your new password is ${newpassword}.
Text/html e-mail with Text/plain alternativeIf an HTML template was defined and a text template exists, then the text template would be used as an alternative message. In our previous example, if both app/views/mails/lostpassword.html andapp/views/mails/lostpassword.txt is defined, then the e-mail would be sent in text/html as defined in lostpassword.html with a alternative part as D Efined in LostPassword.txt. So your can send nice HMTL e-mail to your friends and still please those geeky friends that still use mutt;)
Links to your application in e-mailYour can include links to Your application in e-mails as this:
@@{application.index}
If you send the mails from Jobs, you had to configure Application.baseurl in application.conf.
Application.baseurl must is a valid external BASEURL to your application.
If the website playframework.org where to send your an e-mail from inside a Job, its configuration
Would look like this:
application.baseUrl=http://www.playframework.org/
SMTP ConfigurationE-mail functionality is configured in your application ' s conf/application.conf file. First of all, you need to define the SMTP server to use:
mail.smtp.host=smtp.taldius.net
If your SMTP server requires authentication, use the following properties:
mail.smtp.user=jfpmail.smtp.pass=topsecret
Channel & PortsThere is ways to send the e-mail over an encrypted channel. If your server supports the starttlscommand (SEE:RFC 2487), you can use a clear connection on port Switch to SSL/TLS. Adding this configuration option:
mail.smtp.channel=starttls
Your server may also provide a SMTP-OVER-SSL (SMTPS) connector, which is the SSL socket listening on port 465. In the so case, you tell Play to use this setup using the configuration option:
mail.smtp.channel=ssl
More about ConfigurationUnder the hood, Play uses JavaMail to perform the actual SMTP transactions. If you need to see what's going on, try:
mail.debug=true
When using SSL connections with JavaMail, the default SSL behavior are to drop the connection if the remote server certific Ate is not signed by a root certificate. The particular when using a self-signed certificate. Play ' s default behavior is-to-skip that check. You can control this using the following property:
mail.smtp.socketFactory.class
If you need to connect to servers using non-standard ports, the following property would override the defaults:
mail.smtp.port=2500
Using GmailTo use Gmail's servers, use the This configuration:
mail.smtp.host=smtp.gmail.commail.smtp.user=yourGmailLoginmail.smtp.pass=yourGmailPasswordmail.smtp.channel=ssl
Continuing the discussion
Now we shall move on to testing the application.
Sending e-mail