javax.mail.AuthenticationFailedException:535 5.7.3在具有NTLM的Exchange服务器上,身份验证失败

时间:2018-09-27 09:07:29

标签: java email javamail

客户端要求程序能够通过其Exchange Mail Server发送邮件。
当我在网上寻找一些示例时,遇到了一些页面,这些页面帮助我为发送部分建立了一个小的方法

my_layer


但是,只要程序到达“ Transport.send(message)”部分,就会启动以下异常

private void sendMailYeah() {
    final String username = "user_id"; 
    final String password = "userpassword";

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", "true");
    props.put("mail.smtp.starttls.enable", "false");
    props.put("mail.smtp.from", "the mail to be used);
    props.put("mail.smtp.user",  username);
    props.put("mail.smtp.password", password);
    props.put("mail.smtp.host", "the server to be used");
    props.put("mail.smtp.port", "the port to be used");
    props.put("mail.smtp.auth.mechanisms","NTLM");

    props.put("mail.smtp.auth.ntlm.domain","domain name"); 


    Session session = Session.getInstance(props,new MyAuthenticator(username,password));
    session.setDebug(true);

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("testaddress@testadress.it"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("myaddress@superaddress.com"));
        message.setSubject("Test email");
        message.setText("TEST EMAIL");

        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        e.printStackTrace();
    }
}

  public static class MyAuthenticator extends Authenticator {

        String user;
        String pw;
        public MyAuthenticator (String username, String password)
        {
            super();
            this.user = username;
            this.pw = password;
        }
        public PasswordAuthentication getPasswordAuthentication()
        {
            return new PasswordAuthentication(user, pw);
        }
      }

可能在哪里出现问题?我试过看看是否有人遇到类似问题,但找不到任何东西。我自己也尝试添加属性“ mail.smtp.user”和“ mail.smtp.password”,但这并没有帮助

0 个答案:

没有答案