zoukankan      html  css  js  c++  java
  • 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");

  • 相关阅读:
    Hibernate面试题
    HBuilder开发移动App——manifest.json文件解析
    HTML5+ App开发入门
    Hbuilder开发移动App(1)
    Spring源码 之环境搭建
    java 反射机制
    【LeetCode】Divide Two Integers
    【LeetCode】4Sum
    Java ArrayList、Vector和LinkedList等的差别与用法(转)
    关于Python元祖,列表,字典,集合的比较
  • 原文地址:https://www.cnblogs.com/xiaohanlin/p/12066666.html
Copyright © 2011-2022 走看看