mrandy 2016-05-10 09:34 采纳率: 0%
浏览 2286
已结题

javamail 发送office365 报错

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条回答 默认 最新

  • threenewbee 2016-05-11 01:28
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现