Author |
|
george82 Newbie
Joined: 11 July 2022 Location: India
Online Status: Offline Posts: 3
|
Posted: 11 July 2022 at 8:59am | IP Logged
|
|
|
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 |
|
|
george82 Newbie
Joined: 11 July 2022 Location: India
Online Status: Offline Posts: 3
|
Posted: 11 July 2022 at 10:33am | IP Logged
|
|
|
EWS error code - 701
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 11 July 2022 at 12:34pm | IP Logged
|
|
|
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 |
|
|
george82 Newbie
Joined: 11 July 2022 Location: India
Online Status: Offline Posts: 3
|
Posted: 11 July 2022 at 11:59pm | IP Logged
|
|
|
Great thanks , that fixed the issue
|
Back to Top |
|
|