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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站