I have an app that I use to manage my e-mail account on outlook.com and send e-mail. The detail as to why isn't important, but it has been working for years without issue.
Importantly - this is for a personal e-mail address - e.g [email protected]
It's not a corporate or work account.
It uses basic authentication, with the following code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials(account, main_password);
(account is the e-mail address, and main_password obviously the password).
It appears to authenticate ok, but then when you try to do something on the mailbox (e.g. access particular folders), I get:
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The remote server returned an error: (401) Unauthorized. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request)
--- End of inner exception stack trace ---
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request)
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at Microsoft.Exchange.WebServices.Data.ExchangeService.FindFolders(FolderId parentFolderId, SearchFilter searchFilter, FolderView view)
... when trying to get a FolderID, for example.
As mentioned it has worked fine for years, but in the last couple of weeks has suddenly started throwing this exception.
I've read that Microsoft have been gradually turning off Basic Authentication, so I wonder if that has finally caught up with me?
However, all the examples I can find on migrating to OAuth2 appear to be based on corporate Office365 accounts - and so need registration of the app with the particular tenant in use, and then I need a clientId and tenantID to get the token (see e.g. Using Oauth2 to send email via Office365 C#)
Can anyone please point me to some example C#.NET code for using EWS with a personal outlook.com e-mail address please?
Or, alternatively, if there are any suggestions as to why my code has suddenly stopped working, those are welcome too.