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

Free Support Forum - aspose.com

EWSClient.GetEWSClient

Hi Aspose,

Is there any difference in method definition of GetEWSClient(string mailboxUri, ICredentials credentials) in version 17.6 and 20.9.1.

When I am using 20.9.1 version I am able to connect , but when I am using 17.6 it is throwing 401. So checking on any code change has been made for this method.

Code :

NetworkCredential credentials = new OAuthNetworkCredential(username, accesstoken);
client = EWSClient.GetEWSClient(“https://outlook.office365.com/EWS/Exchange.asmx”, credentials);

Error :
System.Net.WebException: The request failed with HTTP status 401: .
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at #=zh_rHR_BTmjFhTy3oR8$zSfhGEIUaVtr$87WlKkWYrlmqF0tkRA==.#=z$SwyS7A=(String #=zZfSZ0NM=, Object[] #=zsQ6gQPA=)
at #=zh_rHR_BTmjFhTy3oR8$zSfhGEIUaVtr$87WlKkWYrlmqF0tkRA==.GetFolder(GetFolderType GetFolder1)
at Aspose.Email.Clients.Exchange.WebService.EWSClient.GetEWSClient(String mailboxUri, ICredentials credentials, WebProxy proxy)
at Aspose.Email.Clients.Exchange.WebService.EWSClient.GetEWSClient(String mailboxUri, ICredentials credentials)

@suryamohan05

Please upgrade to the latest version of Aspose.Email for .NET 22.8 and use the attached code example to achieve your requirement. Hope this helps you.
EWSModernAuthenticationApp.zip (3.4 KB)