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

Free Support Forum - aspose.com

"The underlying connection was closed", from All Installations

Suddenly the component doesn’t work anymore: “The underlying connection was closed”.
Did Microsoft change something?
We made a further test using your sample app: https://docs.aspose.com/email/net/connecting-to-exchange-server/
It doesn’t work. Same error.
We’re using the latest version. Previous versions don’t work anyway.
We’ve all customers blocked. Please reply urgently.

@albertose,
Thank you for contacting support.

I have checked the code examples from that documentation article for connecting to Office 365 Outlook. They work fine on my side. Please try using ImapClient activity logging to find out the cause of the error.

Documents: ImapClient Activity Logging
API Reference: ImapClient Class

Hi, thank you for the prompt answer.

Actually we’re using EWS, not IMAP.

@albertose,
Thank you for the issue details. You should try to enable activity logging for the EWS in the same way.

I’ve activated the logging but it didn’t help. The “The underlying connection was closed” error occurs before any other information can be printed in the log.
Please note we tried also from a PC outside of our network, to be sure it is not a network issue here.

Sometimes, it doesnt report the “The underlying connection was closed”, but the following errors:

Mailbox information can not be read.
Folder Id: ‘msgfolderroot’; Message: Mailbox does not exist.
Folder Id: ‘calendar’; Message: Mailbox does not exist.
Folder Id: ‘contacts’; Message: Mailbox does not exist.
Folder Id: ‘deleteditems’; Message: Mailbox does not exist.
Folder Id: ‘drafts’; Message: Mailbox does not exist.
Folder Id: ‘inbox’; Message: Mailbox does not exist.
Folder Id: ‘journal’; Message: Mailbox does not exist.
Folder Id: ‘notes’; Message: Mailbox does not exist.
Folder Id: ‘outbox’; Message: Mailbox does not exist.
Folder Id: ‘sentitems’; Message: Mailbox does not exist.
Folder Id: ‘tasks’; Message: Mailbox does not exist.
Folder Id: ‘junkemail’; Message: Mailbox does not exist.

It is not possible is is an issue of the mailbox, since this occurs with different accounts, and it always worked in the past.
You should check if Microsoft made some updates on connections.
It is not possible everything stopped working suddenly!

UPDATE - after many tests with the Exchange 365 organization, I’ve come to this conclusions:

  • downgrading to version 20.12.0 makes the call to EWSClient.GetEWSClient() successful;
  • upgrading to version 21.9.0, makes the connection ALWAYS fail with the two errors above (getting the first one or the second one is random).

What did you change between the two versions regarding the connection method?

@albertose,
We need to reproduce this problem on our side to help you properly. Please share a simple, standalone project without your application code that we can use to reproduce the problem.

Here’s the code, it’s a standard connection code, tested with the two versions of Aspose.Email (20.12.0 : working, and 21.9.0: not working).

string serviceUrl = "https://outlook.office365.com/EWS/Exchange.asmx";
string username = "test@test.onmicrosoft.com";
string password = "*******";

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

var service = EWSClient.GetEWSClient(serviceUrl, username, password);

@albertose,
This code example works fine on my side. It would be great if you could share a simple project because the project settings can hint at the cause of the problem.

Hi @albertose,

We have been fighting this same error with Office365 mailboxes the last day or so ourselves. It has been sporadically working for us so figured it was something on MS side (still do actually).

However, just in case it was something that Aspose was handling, as we have seen these types of things in the past fixed by an Aspose update, we were running 20.11.0 and I just updated to 21.9.0.

After updating Aspose Email, it started working again. I am still running some tests and we probably aren’t out of the woods (especially since you had problems with 21.9.0) but wanted to share as I don’t think it is simply an Aspose problem. MS changed something but I can’t find any notices of changes.

I’ll post if I can figure out any additional details on what is causing this, assuming it continues, which I’m pretty sure it will. :frowning:

After upgrading to 21.9.0, it worked for a while but just got the same “The underlying connection was closed: An unexpected error occurred on a send.” error. Retried sending and it went through fine the second time.

Will try 20.12.0 to see if that makes a difference.

20.12.0 makes no difference for me. Still get successes and failures at the same rough rate (eg. sporadic).

Since this is so inconsistent from one location (seems to work fine from other locations I’ve tested from) I’m starting to think it is some sort of access problem based on what IP outlook.office365.com resolves to. I can see it changing for different requests from the same machine. There might be some firewall rules on the site that isn’t consistently working that is preventing proper comm with the exchange service. I’m going to look into that next.

This sounds different from the problem you might be having though (either always working or always not working) based on Aspose Email version.

@dknudsen-bhip,
Thank you for contacting support. We will reply to you as soon as possible.

@dknudsen-bhip,
Thank you for your help.

If you isolate the problem in Aspose.Email, please describe it in a new forum thread.