Click here to Skip to main content
15,905,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
static void Main(string[] args)

        {

            string UserName = "**";

            string Password = "**";

            string EXCHANGEMAILURL = @"<Exchange Webservice URL>";

            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<Item> findIncomingMails = service.FindItems(xChangeSourceFolder.Id, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false),

                     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

What I have tried:

It was working before, but since last 1-2 weeks, it stopped working.
Posted
Updated 21-Dec-22 3:19am
Comments
Richard Deeming 16-Dec-22 8:39am    
That error suggests your client can't talk to your server. Check the server name specified in EXCHANGEMAILURL, and ensure that DNS on the client resolves the host name to the correct IP address.
Ajit Kumar Nayak 16-Dec-22 9:05am    
Yes..EXCHANGEMAILURL is the asmx service we use - https://west.exch081.serverdata.net/EWS/exchange.asmx and this functionality works on other systems but not on my laptop

I faced same problem all applications used EWS stopped sending emails.Unfortunately, Microsoft stopped Basic authentication on October 1, 2022.

Deprecation of Basic authentication in Exchange Online | Microsoft Learn[^]
Basic Authentication Deprecation in Exchange Online – September 2022 Update - Microsoft Community Hub[^]
 
Share this answer
 
v2
https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-deprecation-in-exchange-online-september/ba-p/3609437
 
Share this answer
 
Comments
Richard Deeming 22-Dec-22 4:26am    
If you want to update your solution, click the green "Improve solution" link and add the missing information. Do not post a second solution just to add another link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900