3

我试图了解我应该如何配置需要传递用户凭据并获取一些邮件内容的网站 (ASP.Net)

根据应用程序池配置,我会收到不同类型的错误,完整的方法是什么?我的意思是代码+配置;o)

我不想写用户和密码,而是通过 Windows 身份验证获取它们

谢谢

代码:

Service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
            {
                Url =
                    new Uri(
                    "https://xxx/yyy.asmx"),
                //UseDefaultCredentials = true doesnt help
            };
        var view = new ItemView(1820);

        // Find the first email message in the Inbox that has attachments. This results
        FindItemsResults<Item> results = Service.FindItems(folderName, view); 
        //Here I get the error 401
4

1 回答 1

4

查看开始使用 EWS 托管 API 客户端应用程序,它涵盖了让您入门的基础知识。请注意,当您使用 UseDefaultCredentials 时,您必须在已加入域的计算机上,并且用户已登录,并且您必须以本地服务器为目标。我们测试了该场景,以下代码在该场景中有效。

using System;
using Microsoft.Exchange.WebServices.Data;

namespace HelloWorld
{
    class Program
    {
        static void Main()
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            service.UseDefaultCredentials = true;
            service.TraceEnabled = true;
            service.TraceFlags = TraceFlags.All;
            //Replace the URL below with your own, but using AutoDiscover is recommended instead
            service.Url = new Uri("https://computer.domain.contoso.com/EWS/Exchange.asmx");

            FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox,
                                                               new ItemView(1));
        }
    }
}

如果这对您不起作用,那么您可能想尝试使用模拟。看到这个线程,我认为他们有类似的情况。有关模拟的更多信息,请参见 MSDN:Exchange 中的模拟和 EWS

于 2014-07-10T20:09:33.767 回答