0
 try {
        Email email = new SimpleEmail();
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator("***@gmail.com", "*********"));
        email.setSSL(true);
        email.setFrom("*******@gmail.com");
        email.setSubject("TestMail");
        email.setMsg("This is a test mail ... :-)");
        email.addTo("*****@gmail.com");
        email.setTLS(true);
        email.send();
    } catch (Exception e) {
        e.printStackTrace();
    }

这是我使用的代码,这是打印堆栈跟踪

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.googlemail.com:587
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at Main.main(Main.java:28)
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:1232)

有人可以告诉我我的代码有什么问题吗?

4

1 回答 1

0

你试过端口 465吗?

并使用email.setSSLOnConnect(true); 而不是 setSSL 和 setTLS ?

于 2012-04-26T18:18:11.183 回答