This Microsoft page指示通过将UseDefaultCredentials属性设置为true,不需要登录名和密码即可与Exchange服务器进行通信。但是,那不是我的经验。Exchange Web Services:UseDefaultCredentials属性
我的代码创建ExchangeService的实例调用的服务:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
如果我手动设置如下凭据,一切都运行得很好:
service.Credentials = new WebCredentials("[email protected]", "my password");
不过,如果我删除了这一行,并我的代码不起作用:
service.UseDefaultCredentials = true;
我有搜索和搜索解决方案,但我没有找到具体的东西。如果有人在这里可以请帮助我,我会非常感激。
编辑: 我试图用我自己的凭据,而不是默认凭据。
string smtpaddress = "[email protected]";
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]");
Folder sharedInbox = Folder.Bind(es, SharedMailbox);
在这一点上,我可以检查包含收件箱的详细信息的sharedInbox。我可以看到未读的电子邮件数量和其他人。
但是,当我访问
ItemView itemView = new ItemView(100);
FindItemsResults<Item> findResults1 = es.FindItems(pqInbox.Id, itemView);
我得到异常“SMTP地址没有与之关联的邮箱”
非常感谢您的见解。我希望找到一种解决方法,将用户名和密码硬编码到代码中,但我会认为这是不可能的。以前,我们的Exchange服务器驻留在我们公司的一台服务器上,但现在我们已迁移到Exchange Online,而我们的Exchange服务器是[blahblahlbah] .outlook.com。 – Jamie 2013-03-20 17:54:03