javamail 发送office365 报错 2C

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个回答

你的邮箱怎么写的,没有附加@后面的部分吧。

mrandy
mrandy 加了
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐