您好,我目前正在开发Java应用程序,将通过Java邮件API(1.6.2)发送邮件给多个收件人,我已经按照微软文档配置了SMTP问题是代码与我的个人Hotmail电子邮件ID,但它失败的企业办公室365帐户。
错误:javax.mail。验证失败异常:535 5.7.3验证不成功[产品编号1PR0101CA0066.INDPRD01.PROD.OUTLOOK.COM]
POP和IMAP正在工作(接收邮件),我可以在Office 365 Web中使用密码登录,我也试过更改密码。
代码:
User user = Credentials.ACC;
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.office365.com");//outlook.office365.com
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");//25
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.transport.protocol", "smtp");
//props.put("mail.smtp.ssl.enable", true);
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user.getUsername(), user.getPassword());
}
});
session.setDebug(true);
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom(user.getUsername());
msg.setRecipients(Message.RecipientType.TO,
"some@mail.com");
msg.setSubject("Testing SMTP using [" + user.getUsername() + "]");
msg.setSentDate(new Date());
msg.setText("Hey, this is a test from [" + user.getUsername() + "], Sending via Java Mail API");
Transport.send(msg);
System.out.println("Sent Ok");
} catch (MessagingException e) {
System.out.println("Something went wrong");
e.printStackTrace();
}
2条答案
按热度按时间eyh26e7m1#
zf9nrax12#
在以下位置禁用STMP的现代身份验证:
https://admin.microsoft.com/Adminportal/Home?source=applauncher#/Settings/Services/:/Settings/L1/ModernAuthentication
请等待几分钟以测试是否进行了这些更改。