Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MS Exchange server
Message
From
26/02/2020 03:35:03
 
 
To
All
General information
Forum:
C#
Category:
Web Services
Title:
MS Exchange server
Miscellaneous
Thread ID:
01673210
Message ID:
01673210
Views:
71
Hi,

I created one short application, which reads emails from MS Exchange, these emails move to another folder (MS Exch.server), then downloads and saves them to hdd as files .eml, and finish write to DB.
it is started via a sch. task.
Sometimes I get the following error:

The request failed. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

ExchangeService _service;

try
{
Console.WriteLine("Registering Exchange connection");

_service = new ExchangeService
{
Credentials = new WebCredentials("username", "password")
};
}
catch
{
Console.WriteLine("new ExchangeService failed. Press enter to exit:");
return;
}

// office365 webservice URL
_service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

string fileName = lc_SaveAsFld + "NameOfLogFile.log";

StringBuilder sb = new StringBuilder(); // BB

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

try
{

sb.Append("\r\n" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss") + " ... " + "reading emails from Inbox " + "\r\n");

// Read 100 mails

int i = 0;

foreach (EmailMessage email in _service.FindItems(WellKnownFolderName.Inbox, new ItemView(50)))
{

email.Load(new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.TextBody, ItemSchema.MimeContent));
Next
Reply
Map
View

Click here to load this message in the networking platform