javamail "535 5.7.3 Authentication unsuccessful" 问题排查

 

有一家odm的服务器用Javamail发邮件的时候报错  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");   //如果不行改为digest再试试
//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");

posted @ 2019-12-19 11:19  kuroniko  阅读(13560)  评论(0编辑  收藏  举报