AutodiscoverLocalException:找不到自动发现服务

时间:2012-08-13 07:09:27

标签: c# .net email exchange-server exchangewebservices

我想使用.NET 3.5访问Exchange服务器。这是我的代码:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
            service.Credentials = new WebCredentials("email_test@xxx.com", "abcd");

            service.AutodiscoverUrl("email_test@xxx.com");

            EmailMessage message = new EmailMessage(service);
            message.Subject = "Interesting";
            message.Body = "The proposition has been considered.";
            message.ToRecipients.Add("abc@xxx.com");
            message.SendAndSaveCopy();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }
}

我指的是this article来编写代码:

但是我收到了这个例外:

  

AutodiscoverLocalException:无法找到自动发现服务。

任何人都可以提供帮助吗?

2 个答案:

答案 0 :(得分:1)

我遇到了这个问题,原因是用户帐户被锁定了。

答案 1 :(得分:1)

service.Credentials = new WebCredentials("<loginID..not email address>", "< the pw>");
service.AutodiscoverUrl("<your emailaddress>",RedirectionUrlValidationCallback);