2016-01-31 21 views
0

我在閱讀關於通過播放框架(java)發送電子郵件的最佳方式。我發現這個:https://github.com/playframework/play-mailer,我按照說明操作。我使用Gmail。java播放框架中的gmail smtp異常

這是我加入application.conf:

play.mailer.host="smtp.gmail.com" 
play.mailer.port=587 
play.mailer.ssl=yes 
play.mailer.tls=no 
play.mailer.user="[email protected]" 
play.mailer.password="blabla" 

,這裏是我的控制器:

Email email = new Email(); 
     email.setSubject("Confirmation"); 
     email.setFrom("Mister FROM <[email protected]>"); 
     email.addTo("Miss TO <[email protected]>"); 
     email.setBodyText("A text message"); 
     email.setBodyHtml("<html><body><p>An <b>html</b> message</p></body></html>"); 
     mailerClient.send(email); 

一切都沒有問題,編譯,但是當我運行它,我得到這個異常:

[EmailException: Sending the email to the following server failed : smtp.gmail.com:587] at mailerClient.send(email); 

回答

1

您必須更改gmail配置的更改。 like- 轉到您的Gmail帳戶,然後在設置部分轉到「轉發和POP/IMAP」選項卡,然後啓用「啓用IMAP」。

希望這可以幫助您發送正確的憑證。

+0

我啓用了IMAP,因爲它之前被禁用。但仍然發生山姆異常。 – xpg94

+0

使用java郵件API而不是這個。 http://www.javatpoint.com/example-of-sending-email-using-java-mail-api https://www.arclab.com/en/kb/email/list-of-smtp-and -imap-servers-mailserver-list.html – Samir

+0

我設法使用apache commons發送郵件,它使用java郵件API。謝謝 – xpg94