Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET EWS Component

 AfterLogic Forum : MailBee.NET EWS Component
Subject Topic: EWS and .net 4.5.1 - error Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
george82
Newbie
Newbie


Joined: 11 July 2022
Location: India
Online Status: Offline
Posts: 3
Posted: 11 July 2022 at 8:59am | IP Logged Quote george82

When i tried to access using EWS in a net 4.5.1 frame work get , i get the following error. The same works prefectly fine when tried in a .net core 3.1 env


IConfidentialClientApplication app = ConfidentialClientApplicationBuilder
                 .Create(ClientId)
                 .WithClientSecret(ClientSecret)
                 .WithTenantId(Tenant)
                 .Build();

            // The permission scope required for EWS access
            var ewsScopes = new string[] { "https://outlook.office365.com/.default" };


            // Make the token request
            var authResult = app.AcquireTokenForClient(ewsScopes).ExecuteAsync();
            var authCredentials = new OAuthCredentials(authResult?.Result?.AccessToken);

            // Access Office365 mailbox
            var ewsClient = new Ews();
            ewsClient.InitEwsClient(ExchangeVersion.Exchange2010_SP1, TimeZoneInfo.Utc);
            ewsClient.SetServerUrl("https://outlook.office365.com/EWS/Exchange.asmx");
            ewsClient.SetCredentials(authCredentials);
            ewsClient.Service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, Email);

            // Retrieve information on Inbox and load the newest message
       

            FolderId foldId = ewsClient.FindFolderIdByFullName("Inbox");

The above line throws the below error


: 'Server-side Exchange error occurred. InnerException message follows: The request failed. The underlying connection was closed: An unexpected error occurred on a send. InnerException message follows: The underlying connection was closed: An unexpected error occurred on a send.'

stackTrace -    at a.m.a.a(FolderId A_0, FolderView A_1, SearchFilter A_2, Boolean A_3, Nullable`1 A_4, Nullable`1 A_5)
   at a.m.a.a(FolderId A_0, String A_1, Boolean A_2)
   at a.m.b.a(FolderId A_0, String A_1, Boolean A_2, Int32 A_3)
   at a.m.b.a(Boolean A_0, FolderId A_1, String A_2, Boolean A_3, Int32 A_4)
   at MailBee.EwsMail.Ews.FindFolderIdByFullName(String folderFullName)
Back to Top View george82's Profile Search for other posts by george82
 
george82
Newbie
Newbie


Joined: 11 July 2022
Location: India
Online Status: Offline
Posts: 3
Posted: 11 July 2022 at 10:33am | IP Logged Quote george82

EWS error code - 701
Back to Top View george82's Profile Search for other posts by george82
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 11 July 2022 at 12:34pm | IP Logged Quote Alex

I bet it's something with TLS version. .NET Core will use the modern TLS 1.2 or TLS 1.3 by default why .NET Framework 4.5 will not.

Try adding this at the top of your code:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

Regards,
Alex

Back to Top View Alex's Profile Search for other posts by Alex
 
george82
Newbie
Newbie


Joined: 11 July 2022
Location: India
Online Status: Offline
Posts: 3
Posted: 11 July 2022 at 11:59pm | IP Logged Quote george82

Great thanks , that fixed the issue
Back to Top View george82's Profile Search for other posts by george82
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide