mrandy
mrandy
采纳率0%
2016-05-10 09:34 阅读 2.2k

javamail 发送office365 报错

2

public static void main(String[] args) throws GeneralSecurityException {
String emailFrom = from;
Authenticator authenticator = new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("邮箱", "密码");
}
};

    Properties properties = new Properties();
    properties.setProperty("mail.smtp.host", "smtp.office365.com");
    properties.setProperty("mail.smtp.port", "587");
    properties.setProperty("mail.smtp.auth", "true");
    properties.setProperty("mail.debug", "true");  
    properties.setProperty("mail.smtp.starttls.enable", "true");

    Session session = Session.getInstance( properties, authenticator );
    try
    {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(emailFrom));
        InternetAddress[] to = {new InternetAddress("邮箱")};
        message.setRecipients(Message.RecipientType.TO, to);
        message.setSubject("PLACE_SUBJECT_HERE");
        message.setText("YOUR_MESSAGE_HERE");
        Transport.send(message);
    }
    catch (MessagingException exception)
    {
        exception.printStackTrace();
    }
}

报错:
javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful
账号和密码又是对的。求解

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐