2016-05-25 4 views
1

添付ファイル付きの電子メールをPlay Frameworkに送信するページを作成しようとしています。私はまず簡単な電子メールを送る方法を知る必要があります。私は次のとおりです Apache Commons Userguide for EmailPlay Framework Apache Commonsを使用して電子メールを送信する

Email email = new SimpleEmail(); 
     email.setHostName("smtp-mail.outlook.com"); 
     email.setSmtpPort(587); 
     email.setAuthenticator(new DefaultAuthenticator("[email protected]", "password")); 
     email.setSSLOnConnect(true); 
     email.setFrom("[email protected]"); 
     email.setSubject("Subject"); 
     email.setMsg("This is a test mail ... :-)"); 
     email.addTo("[email protected]"); 
     email.send(); 

実行例外:プログラムが受け入れる理由は何Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp-mail.outlook.com, 465; timeout 60000;

[EmailException: Sending the email to the following server failed : smtp-mail.outlook.com:465]

それは465でも私は、端末上の587

例外としてポートを設定すると言う理由を私は知りませんポート番号は465です。私はGmailの

答えて

0
It's answered in http://stackoverflow.com/questions/26393906/error-sending-email-with-gmail. 

You have to login to "https://www.google.com/settings/security/lesssecureapps" for google and enable then run the program. It works. 

If it's not enabled we get the following exception 
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.googlemail.com:465 
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421) 
    at org.apache.commons.mail.Email.send(Email.java:1448) 
    at EmailTest.main(EmailTest.java:19) 
Caused by: javax.mail.AuthenticationFailedException 
    at javax.mail.Service.connect(Service.java:306) 
    at javax.mail.Service.connect(Service.java:156) 
    at javax.mail.Service.connect(Service.java:105) 
    at javax.mail.Transport.send0(Transport.java:168) 
    at javax.mail.Transport.send(Transport.java:98) 
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411) 
    ... 2 more 


(This is for gmail) 
を使用する場合

同じ問題も発生し

関連する問題