I have to establish connectivity with Microsoft Exchange Webservice and I have been given the below details -
Shared mailbox address is say -
"students@student.edu"
Service account is say -
"Student SA"
Password for service account is say -
"Pass1234"
I followed the code sample given in website:
Below is my code sample using the above details -
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("Student SA", "Pass1234");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("students@student.edu", RedirectionUrlValidationCallback);
// service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "myADAccount");
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
When I run this locally, I am getting below error messages
<Trace Tag="AutodiscoverConfiguration" Tid="9" Time="2018-06-04 15:10:07Z">
Request error: The remote server returned an error: (401) Unauthorized.
</Trace>
I looked for the same in other threads here How to connect to Exchange?
and also on Code project, but they all tell the same way on how to connect to exchange webservice.
I am not sure as to why I am getting the unauthorized access in Autodiscover
configuration and if I am using the correct code to connect to exchange server using the service account information that has been provided.