Modern authentication to shared Exchange365 mailboxes via VB.Net winforms

Hi

We are being required to use modern authentication to connect shared mailboxes on Exchange365.

I have downloaded an example C# application (EWSModernAuthenticationApp.zip) and using this can successfully connect to our shared mailbox.

Converting this console application to VB.Net (VBNetEWSConsoleApplication.zip) and running it gives the following error
See Error.png
Changing the highlight line to say ”accessToken.Result” as below works and connects to the mailbox.

Dim credentials As NetworkCredential = New OAuthNetworkCredential(photos@face2facecontact.co.uk, accessToken.Result)

Taking this code and adding it to a VB.Net WinForms test application (WinFormsConnectSharedMailbox.zip). On clicking Button1 to fire the code, the application hangs and doesn’t return a valid token.

We are using aspose.email 23.1 for all the projects.

Please can you advise, how can I connect to an Exchange shared mailbox using modern authentication in an VB.Net WinForms application?

Regards
Ian TyrrellError.PNG (58.3 KB)
WinFormsConnectSharedMailbox.zip (3.7 MB)
VBNetEWSConsoleApplication.zip (3.9 MB)
EWSModernAuthenticationApp.zip (4.3 MB)

Hello,

We have opened the new investigation ticket in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): EMAILNET-40950

Thanks.

Hello @Ian_Tyrrell,

The issues you described are not related to Aspose.Email.
You need to look at how to work with asynchronous functions in VB.NET.

Changing the highlight line to say ”accessToken.Result” as below works and connects to the mailbox.

That’s right, because you’re calling an asynchronous function from a non-asynchronous Main method.

On clicking Button1 to fire the code, the application hangs and doesn’t return a valid token.

As for the WinForm app, we modified it to make it work. WinFormsConnectSharedMailbox_Corrected.zip (6.0 KB)
Please review VB.NET asynchronous programming carefully.

Thank you.