![](/img/trans.png)
[英]error while sending email in Java using Apache Commons email libs
[英]Play Framework Sending Email by using Apache Commons
我正在嘗試創建一個頁面,在Play Framework上發送帶附件的電子郵件。 我首先需要知道如何發送簡單的電子郵件。 我正在關注Apache Commons Userguide for Email 。
Email email = new SimpleEmail();
email.setHostName("smtp-mail.outlook.com");
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator("email@outlook.com", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@outlook.com");
email.setSubject("Subject");
email.setMsg("This is a test mail ... :-)");
email.addTo("add@outlook.com");
email.send();
執行異常: [EmailException: Sending the email to the following server failed : smtp-mail.outlook.com:465]
我不知道為什么它說465
甚至我將端口設置為587
終端上的異常: Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp-mail.outlook.com, 465; timeout 60000;
Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp-mail.outlook.com, 465; timeout 60000;
程序接受端口號為465
的原因是什么。
使用gmail時也會出現同樣的問題
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.