We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Error accessing mail services using OAuth2

Hi,

I’m trying to create imapClient providing access token (obtained by login with MSAL library) directly into the constructor of the client, but i get an error “Unable connect to the server”, why that happen?

I’m using the first example of this tutorial https://docs.aspose.com/email/net/access-mail-services-using-oauth/

StackTrace:
image.png (13.6 KB)

@RODRIGOBPT,

Refer to the following article about prerequisite settings, getting a token using MSAL and connection using ImapClient. Thanks.

1 Like

Doesnt work with hotmail? Its only for microsoft365? This account have securities default enabled. As the server, i tried “outlook.office365.com” and “imap-mail.outlook.com”, but it never works.

image.png (79.9 KB)

@RODRIGOBPT,

I assume this should work with hotmail.
You need to specify the TenantId as well:

var pca = PublicClientApplicationBuilder
                            .Create(ClientId)
                            .WithTenantId(TenantId)
                            .WithRedirectUri(RedirectUri)
                            .Build();

Thanks.