we are trying to login outlook.com in our app by using oauth2.0, we have done the registration of app AAD. App authenticates the user successfully and responds with the access_token, now further we wanted to read the emails from imap server and here we are getting failure, please try and help us out with this.
Kindly find below error we are getting.
- OK The Microsoft Exchange IMAP4 service is ready. [UABOADIAUABSADAAMQBDAEEAMAAwADYAMgAuAEkATgBEAFAAUgBEADAAMQAuAFAAUgBPAEQALgBPAFUAVABMAE8ATwBLAC4AQwBPAE0A] A0 CAPABILITY
- CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+ A0 OK CAPABILITY completed. DEBUG IMAPS: AUTH: PLAIN DEBUG IMAPS: AUTH: XOAUTH2 DEBUG IMAPS: protocolConnect login, host=outlook.office365.com, [email protected], password= DEBUG IMAPS: mechanism PLAIN disabled by property: mail.imaps.auth.plain.disable DEBUG IMAPS: mechanism LOGIN not supported by server DEBUG IMAPS: mechanism NTLM not supported by server A1 AUTHENTICATE XOAUTH2 dXNlcj1zaWNjc2FuZGFAb3V0bG9vay5jb20BYXV0aD1CZWFyZXIgRXdCd0E4bDZCQUFVNms3K1hWUXprR3lNdjdWSEIvaDRjSGJKWVJBQUFhbWdZWE81azJ2NEVQYmduSE5BWUcyNENWYXJ4V2dEek9lZ2E2S0J0SGZKcDVkV1hkK3E5T2ExSEJocitIQW1JWVJBRkh6NWxFRWJJRFdGZVF6MGU5U0pRNzZzVnYwUVhXVFFRRUExSktRSmdHdm51Z3QrV2dvd1pJUUxmcVJBQmh2Mm02WWk4bDlWU1FGS1pzV2lpY000blYzWElza0RyYWlWRTNjU2ZMS0tmK09MUDg4OHNCNnVPbzlOWDNXYnZFWUdZTGVMbVpjUG5NOUlrK3MzazhYQWtpOWY2VTl6MGFjUHdKQWRsbk9JZElvNzJQYjhYeXJmVDB6OHpFV2ExRm8xVVpiUHJvdnIrakd1NTJhcjMyaVlZWnpkSDhxaGhZRFRFcTJOQnhOUDVaV1d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Hc3SGpuY3JYcHBXdkEydFRzclNWVVkwSDhJS2lpU0hBZz09AQE= A1 NO AUTHENTICATE failed.
Please find thecode for connection:
properties.put("mail.imaps.host", "outlook.office365.com");
properties.put("incomingHost", "outlook.office365.com");
properties.put("outgoingHost", "smtp.office365.com");
properties.put("mail.imaps.ssl.enable", "true");
//properties.put("mail.imaps.sasl.enable", "true");
properties.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
// properties.put("mail.imap.auth.login.disable", "true");
properties.put("mail.imaps.auth.plain.disable", "true");
//properties.put("mail.imaps.auth.plain.disable", "true");
properties.put("mail.debug", "true");
properties.put("mail.debug.auth", "true");
properties.setProperty("mail.imaps.ssl.trust", "*");
properties.setProperty("mail.smtp.starttls.enable","true");
this.store = session.getStore("imaps");
store.connect("outlook.office365.com", "[email protected]", "access_token");