final String smtpAuthPassword = "*********";
String emailFrom = "**********";
String emailTo = "*********888";
Authenticator authenticator = new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(smtpAuthUserName, smtpAuthPassword);
}
};
Properties properties = new Properties();
properties.setProperty("mail.smtp.host", "outlook.office365.com");
properties.setProperty("mail.smtp.port", "587");
properties.setProperty("mail.smtp.auth", "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(emailTo)};
message.setRecipients(Message.RecipientType.TO, to);
message.setSubject("PLACE_SUBJECT_HERE");
message.setText("YOUR_MESSAGE_HERE");
Transport.send(message);
}
catch (MessagingException exception)
{
exception.printStackTrace();
}
我正在尝试使用上述代码通过Java Office电子邮件(Outlook)从Java发送电子邮件。即使凭据正确无误,也出现以下异常。有人可以告诉我如何解决吗?
javax.mail.AuthenticationFailedException:535 5.7.3身份验证失败
当我检查日志时,有这样的日志, 调试SMTP:protocolConnect登录,主机= smtp.office365.com,用户=xxxxxr@xxxx.au,密码=
我的PW是否为NULL?我的代码有问题吗?