2014-02-20 30 views
0

我想用play farmework發送電子郵件。配置我application.conf無法使用Play Framework發送電子郵件1.2.5

# 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 

我創建/views/Mails/welcome.html一個新的模板電子郵件和welcome.txt 而我寫的靜態方法將是一個電子郵件發送者

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(); 
    } 
} 

我在輸出控制檯消息

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() 

最後我沒有收到郵件。 請幫助。謝謝。

+0

任何錯誤信息?你確定你的'welcome()'方法被執行了嗎? – Carsten

+0

是的。我在welcome()中插入兩個System.out.println(),並且application.conf中的mail.debug起作用。 **輸出控制檯消息**'開始功能WELCOM() 09:41:50499 INFO〜從模擬郵遞員 接收\t新電子郵件通過 \t來自:[email protected] \t的ReplyTo:vincnet.iam @ gmail.com \t若要:「[email protected]」<[email protected]> \t主題:測試發送郵件 \t text/plain; charset = UTF-8:hello world \t text/html;字符集= UTF-8: \t \t \t

世界,你好

\t \t 完成功能的開山鼻祖()' – user3333187

+0

你應該更好的編輯問題,包括日誌,而不是發佈這一切在註釋。閱讀起來很方便。 :)無論如何,從「模擬梅勒」表明你並不真的發送電子郵件。你的配置中是否有'mail.smtp = mock'? – Carsten

回答

2

你也行

mail.smtp=mock 

application.conf地方。這使得Play使用模擬郵件程序而不是通過SMTP服務器進行郵件發送。默認行爲是在DEV模式下使用模擬郵件程序並在PROD模式下使用SMTP郵件程序。您可以通過在配置中註釋掉所提到的行來更改此行爲。

另請注意,您不應該再使用Play 1.2.5。 1.X分支的當前最新版本是1.2.7。您的版本1.2.5包含一個session injection vulnerability