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

空扰寡人 提交于 2019-12-05 15:41:33

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.

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.

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));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!