2 mrandy mrandy 于 2016.05.10 17:34 提问

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

caozhy
caozhy   Ds   Rxr 2016.05.11 09:28

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

mrandy
mrandy 加了
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!