I read emails from an exchange online account using imap.
This worked without problem using basic authentication. Since basic authentication will be disabled by exchange online, i need to authenticate via oAuth.
I did follow the documentation on Access Mail Services using OAuth|Documentation
As described in the documentation, i’ve implemented the AzureROPCTokenProvider and configured the Exchange App Registration according to the documentation from microsoft.
The implementation AzureROPCTokenProvider seems to work and i do get a token.
image.png (50.3 KB)
This code is used for loading emails via IMAP
using (ImapClient client = new ImapClient(
“outlook.office365.com”,
993,
userName,
tokenProvider,
SecurityOptions.SSLImplicit))
{
//When this method is called, AzureROPCTokenProvider.GetAccessToken is called first
[//AzureROPCTokenProvider.GetAccessToken](https://azureropctokenprovider.getaccesstoken/) returns a valid token
//Then the exception “Unable connect to the serve” occurs
var lst = client.ListMessages();
}
The exception is “Unable connect to the server” without any further information.
Is there a way to get more useful information what exactly is not working.
Since the token can be loaded, the server seems to be available and based on the exception message it is not clear what is wrong.
Message: Unable connect to the server.
Stack Trace: at #=z1zUrGj5sxf9uqcjTJVcVa2E7dMDr.#=zBazcka0=(IAsyncResult #=zQXkmzSo=)
at #=z1zUrGj5sxf9uqcjTJVcVa2E7dMDr.#=zaksmQ6s=()
at #=z_wnR4kxf0caXFBC6Gp9X7XGpTiOTg2vkkWiZUFA=.#=zFgPZw88=(#=zzdacdi9nZ_EWsncM6CvfmmlYFeXpSJT00g== #=zpgkRhnk=)
at #=zmXwX_0NGShfKfH1ZqtD7kQ3Kx89t.#=zxJKUZtSBJVbV(Int32 #=zytvRPTU=, #=zzdacdi9nZ_EWsncM6CvfmmlYFeXpSJT00g== #=zkkiUCAA=, List`1 #=zbj3Ohq4=, Int32 #=zbK1AP4k=)
at #=zmXwX_0NGShfKfH1ZqtD7kQ3Kx89t.#=zxJKUZtSBJVbV(Int32 #=zbK1AP4k=, #=zzdacdi9nZ_EWsncM6CvfmmlYFeXpSJT00g== #=zkkiUCAA=, #=zcmd7ccUCbZD5dS3XOwh93Os= #=zoTRekHfrrNPb, List`1 #=zbj3Ohq4=)
at #=zmXwX_0NGShfKfH1ZqtD7kQ3Kx89t.#=zMUR_SbDdZ5go(Int32 #=zbK1AP4k=, #=zzdacdi9nZ_EWsncM6CvfmmlYFeXpSJT00g== #=zkkiUCAA=)
at #=z1zUrGj5sxf9uqcjTJVcVa2E7dMDr.#=z$S2KR0yn2RAT()
at #=z1zUrGj5sxf9uqcjTJVcVa2E7dMDr.#=zxCVEsC8=(AsyncCallback #=zE_F5kXw=, Object #=zW6FV2wk=)
at Aspose.Email.Clients.Imap.ImapClient.#=zstPvzD4qxZ8L(IConnection #=zI2W9bpw=, String #=zXuPejhM=, Int64 #=z6OxiGjHloJPV, Boolean #=zs$G70cvnVz6Q, IEnumerable`1 #=zGJgsRiNqUovN, AsyncCallback #=zE_F5kXw=, Object #=zW6FV2wk=)
at Aspose.Email.Clients.Imap.ImapClient.ListMessages()
at PopImapOAuthAsposeDemo.Program.Main(String[] args) in C:\project\EvidenceGit\PopImapOAuthAsposeDemo\PopImapOAuthAsposeDemo\PopImapOAuthAsposeDemo\Program.cs:line 55