从.net Web应用程序访问Outlook Web服务的凭据

时间:2012-04-06 10:43:47

标签: .net outlook

从内部网上部署的.net Web应用程序中使用:

<authentication mode="Windows" />
<identity impersonate="true" />
在web.config中,我需要能够让用户输入日期和时间以及电子邮件地址,并将日期和时间作为约会添加到电子邮件地址的日历中。

为了开始工作,我想我会尝试访问邮箱并获取10条消息的主题:

ExchangeService myService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

myService.Credentials = new WebCredentials("jsmith", "mypassword");

myService.AutodiscoverUrl("fred.bloggs@mycompany.com");

FindItemsResults<Item> myResults = myService.FindItems(WellKnownFolderName.Inbox, new ItemView(10));

哪种作品。我收到了10个电子邮件主题的列表 - 但是,无论我作为AutodiscoverUrl方法的参数放入哪个电子邮件地址 - 我的最后10封电子邮件的10个主题总是被返回。我如何访问Fred Bloggs电子邮件,当我实现这一点时,访问他的日历(这是我实际需要做的)并输入约会?谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

您作为myService.AutodiscoverUrl参数提供的电子邮件仅用于查找服务。因此,对于所有电子邮件,您可能会为来自同一域的所有电子邮件获得相同的服务。要访问其他用户收件箱,您需要转到他们的文件夹(如果您有适当的权利)。

Microsoft.Exchange.WebServices.Data.FolderId _cal = new Microsoft.Exchange.WebServices.Data.FolderId(WellKnownFolderName.Inbox, new Mailbox("fred.bloggs@mycompany.com"));
Folder rootfolder = Folder.Bind(myService,  _cal);
FindItemsResults<Item> myResults = rootfolder.FindItems(new ItemView(10));