Reputation: 1857
My IMAP code to check emails at Office 365 just stopped working last fall (client didn't notice until just recently).
This is my code. It dies at the login:
Chilkat.Global glob = new Chilkat.Global();
var success = glob.UnlockBundle("MyUnlockCode");
if (success != true)
{
log.LogError("ProcessLatestEmails. Error unlocking component: " + imap.LastErrorText);
return false;
}
// To use a secure TLS/SSL connection, set the Ssl property and the port:
imap.Ssl = UseSSL;
imap.Port = Port;
success = imap.Connect(Server);
if (success != true)
{
log.LogError("ProcessLatestEmails. Error connecting to server: " + imap.LastErrorText);
return false;
}
success = imap.Login(UserName, Password);
if (success != true)
{
log.LogError("ProcessLatestEmails. Error logging in: " + imap.LastErrorText);
imap.Disconnect();
imap.Dispose();
return false;
}
This is error that is returned:
ProcessLatestEmails. Error logging in: ChilkatLog:
Login:
DllDate: Dec 29 2022
ChilkatVersion: 9.5.0.93
UnlockPrefix: UnlockCodeWasHere
Architecture: Little Endian; 64-bit
VerboseLogging: 0
imapServer: outlook.office365.com
loginX(2797ms):
login: [email protected]
greeting: * OK The Microsoft Exchange IMAP4 service is ready. [QgBZAEEAUABSADIAMgBvAGQALgBv...AHUAdABsAG8AbwBrAC4AYwBvAG0A]authenticateLogin(2797ms):
loginImap(2797ms):
ConnectionType: SSL/TLS
ImapCmdSent: aaab LOGIN "[email protected]"
getCompleteResponse(2797ms):
ImapCmdResp: aaab NO LOGIN failed.
--getCompleteResponse
--loginImap
isOK: serverResponse: aaab NO LOGIN failed.
--isOK
--authenticateLogin
--loginX
Failed.
--Login
--ChilkatLog
I verified that IMAP is still enabled for all accounts. I also verified that the passwords are correct.
Is this a deprecated pattern and I need to figure out OAuth or can I get it working.
I am using ChilkatDnCore31 v9.5.0.93 and running this is an Azure Functions instance.
Upvotes: 0
Views: 828
Reputation: 1624
Chilkat published more information and examples for OAuth2 w/ Office365 and MS Exchange. The blog post that summarizes and serves as a good starting point is
https://cknotes.com/office365-modern-authentication-for-imap-pop3-and-smtp/
It has links to other posts and examples for more detailed information. Please have a look to see if it helps.
*** Also, in the Azure AD console where you create your App, create a "web app" -- even though technically it's not a web app, your application is acting as a temporary web server when Chilkat (in a background thread) receives the redirect..
*** Also, make sure to understand the Microsoft account types w.r.t. your registered App: https://learn.microsoft.com/en-us/security/zero-trust/develop/identity-supported-account-types You'll want to choose the appropriate account type for your App defined in Azure based on your needs.
Upvotes: 0