简体   繁体   中英

Failed to send email with Play Framework 1.2.5

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
mail.smtp.user=mymail@gmail.com
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("target@gmail.com");
        setFrom("Me <me@me.com>");
        send();
    }
}

I have in my output console message

begin function welcom()
10:30:36,857 INFO  ~ From Mock Mailer


New email received by   
        From: me@me.com     
        ReplyTo: me@me.com  
        To: "target@gmail.com" <target@gmail.com>
        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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM