javamail "535 5.7.3 Authentication unsuccessful"

JavaMailSenderImpl认证异常了,出现:javax.mail.AuthenticationFailedException: failed to connect的异常,
将JAVAMAIL的DEBUG日志打开,通过properties.setProperty("mail.debug", "true");可以看到出现了535 5.7.3 Authentication unsuccessful的问题,需要增加以下设置:
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.auth.mechanisms", "NTLM");
就可以解决了,如果非WINDOWS操作系统,需要将NTLM修改为digest方式;
具体代码如下:
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.auth.mechanisms", "NTLM");
//properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 
properties.setProperty("mail.debug", "true");
senderImpl.setJavaMailProperties(properties);
senderImpl.setHost("IP地址");
senderImpl.setUsername("认证用户邮箱");
senderImpl.setPassword("对应的邮箱密码");
//senderImpl.setPort(25);

MimeMessage mailMessage = senderImpl.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,
true, "GBK");

你可能感兴趣的:(Authentication)