I am facing an issue while reading emails from my exchange email account using EWS Microsoft API.
Please help me with a solution if anybody has
Used below code
static void Main(string[] args)
{
string UserName = "**";
string Password = "**";
string EXCHANGEMAILURL = @"
ExchangeService service = new ExchangeService();
service.Timeout = 500000;
service.Credentials = new NetworkCredential(UserName, Password);
service.Url = new Uri(EXCHANGEMAILURL);
try
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
FindFoldersResults folderSearchResults = service.FindFolders(WellKnownFolderName.MsgFolderRoot, new FolderView(int.MaxValue));
Folder xChangeSourceFolder = folderSearchResults.Folders.ToList().Find(
f => f.DisplayName.Equals("Inbox", StringComparison.CurrentCultureIgnoreCase));
ItemView itemView = new ItemView(50);
FindItemsResults
new ItemView(50));
Item item = findIncomingMails.First();
EmailMessage messageHTML = (EmailMessage)item;
messageHTML.Load(new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments, ItemSchema.Body) { RequestedBodyType = BodyType.HTML });
string htmlString = messageHTML.Body.Text.ToString();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred : " + ex.StackTrace);
}
}
The exception
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period of time,or established connection failed because connected host has failed to respond
Deepak TewatiaPosted Dec 18, 2022, 4:12 AM
Hi Ajit,
It looks like you are experiencing a connection issue when trying to access your Exchange email account using the EWS (Exchange Web Services) API. Here are a few things you can try to troubleshoot and resolve the issue: