这个微软页面 http://msdn.microsoft.com/en-us/library/exchange/ff597939%28v=exchg.80%29.aspx表示通过将 UseDefaultCredentials 属性设置为 true,无需登录名和密码即可与 Exchange 服务器进行通信。然而,这不是我的经验。
我的代码创建一个名为 service 的 ExchangeService 实例:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
如果我按如下方式手动设置凭据,则一切正常:
service.Credentials = new WebCredentials("[email protected] /cdn-cgi/l/email-protection", "my password");
但是,如果我删除该行并将其替换为以下内容,我的代码将不起作用:
service.UseDefaultCredentials = true;
我一直在寻找解决方案,但没有找到任何具体的东西。如果这里有人可以帮助我,我将非常感激。
编辑:
我尝试使用我自己的凭据而不是默认凭据。
string smtpaddress = "[email protected] /cdn-cgi/l/email-protection";
es.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
es.Credentials = new WebCredentials("myemail", "mypassword");
es.AutodiscoverUrl(smtpaddress, RedirectionCallback);
FolderId SharedMailbox = new FolderId(WellKnownFolderName.Inbox, "[email protected] /cdn-cgi/l/email-protection");
Folder sharedInbox = Folder.Bind(es, SharedMailbox);
此时我可以检查包含收件箱详细信息的sharedInbox。我可以看到未读电子邮件数量和其他信息。
但是当我访问
ItemView itemView = new ItemView(100);
FindItemsResults<Item> findResults1 = es.FindItems(pqInbox.Id, itemView);
我收到异常“SMTP 地址没有与之关联的邮箱”