Connection to Office 365 by EWS API

前端 未结 2 1817
春和景丽
春和景丽 2020-12-03 10:40

I am using EWS API in my console application to process mailbox items and my connection script looks like

ExchangeService service = new ExchangeService(Excha         


        
相关标签:
2条回答
  • 2020-12-03 10:55

    You can use the code below to connect to the EWS on office 365:

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
    
    service.Credentials = new WebCredentials("emailService@domain.com", "password");
    service.AutodiscoverUrl("emailService@domain.com", RedirectionUrlValidationCallback);
    

    You need define one callback function for the AutodiscoveryUrl function, like this:

    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;
    }
    
    0 讨论(0)
  • 2020-12-03 11:06

    I know this is a fairly old solution, but it was still very helpful to me. I have a few tools that worked with the "normal" network version of Exchange, but so far my tests with Exchange Online failed (i got errors like "The Autodiscover service couldn't be located", etc).

    Essential here is to use WebCredentials instead of NetworkCredential and a e-mailaddress instead of a username.

    0 讨论(0)
提交回复
热议问题