2016-05-25 11 views
1

Ich versuche, eine Seite zu erstellen, die eine E-Mail mit Anhang auf Play Framework sendet. Ich muss zuerst wissen, wie man eine einfache E-Mail sendet. Ich folge Apache Commons Userguide for Email.Play Framework Senden von E-Mail mithilfe von 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(); 

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

Ich weiß nicht, warum sagt es 465 auch ich gesetzt Port als 587

Ausnahme auf Terminal: Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp-mail.outlook.com, 465; timeout 60000;

Was ist der Grund, dass Programm akzeptiert Portnummer als 465.

gleiche Problem tritt auch auf, wenn ich gmail verwenden

Antwort

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)