问题描述
- 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
账号和密码又是对的。求解
解决方案
你的邮箱怎么写的,没有附加@后面的部分吧。
时间: 2024-09-17 04:08:44