Use Javamail for accessing Microsoft Exchange mailboxes (IMAP, MS Exchange)

前端 未结 3 1240
庸人自扰
庸人自扰 2021-01-06 02:18

I need to connect to a Microsoft Exchange Server through IMAPS JavaMail. First, I got the:

A1 NO AUTHENTICATE failed.
javax.mail.AuthenticationFailedExcepti         


        
相关标签:
3条回答
  • 2021-01-06 03:11

    You need to use a newer version of JavaMail that supports NTLM authentication. The latest version is 1.5.1.

    Also, see this list of common mistakes.

    0 讨论(0)
  • 2021-01-06 03:12

    It will workout if the username and the mail id both are same.

    For example: system username is john and mail id john@test.com

    IMAP is try to login the mail id using the username "john" from john@test.com, if the user id is differ it will not login.

    0 讨论(0)
  • 2021-01-06 03:12

    Try using your own Authenticator

    public class ExchangeAuthenticator extends Authenticator {
    
        String username;
        String password;
    
        public ExchangeAuthenticator(String username, String password) {
            super();
            this.username= username;
            this.password= password;
        }
    
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    }
    

    and in your code add

    session = Session.getInstance(props,new ExchangeAuthenticator(username, password));
    
    0 讨论(0)
提交回复
热议问题