Exchange Web服务:UseDefaultCredentials属性 [英] Exchange Web Services: UseDefaultCredentials property

查看:124
本文介绍了Exchange Web服务:UseDefaultCredentials属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此Microsoft页面表示通过将UseDefaultCredentials属性设置为true,不需要登录名和密码即可与Exchange服务器进行通信。但是,这不是我的经验。

This Microsoft page indicates that by setting the UseDefaultCredentials property to true, no login name and password are required to communicate with the Exchange server. However, that is not my experience.

我的代码创建了一个称为service的ExchangeService实例:

My code creates an instance of ExchangeService called service:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

如果我按如下方式手动设置凭据,则一切正常:

If I manually set the credentials as follows, everything works just fine:

service.Credentials = new WebCredentials("my@email.address", "my password");

但是,如果我删除该行并将其替换为以下内容,我的代码将无法正常工作:

However, if I remove that line and replace it with the following, my code doesn't work:

service.UseDefaultCredentials = true;

我已经搜索并搜索了解决方案,但没有找到任何具体的解决方案。如果有人可以帮助我,我将不胜感激。

I have searched and searched for solutions but I'm not finding anything concrete. If someone here could please help me I would be very grateful.

编辑:
我尝试使用自己的凭据代替默认凭据。

I tried to use my own credentials instead of the Default Credentials.

string smtpaddress = "somesharedsmtp@domain.com";
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, "somesharedsmtp@domain.com");
Folder sharedInbox = Folder.Bind(es, SharedMailbox);

此时,我可以检查包含收件箱详细信息的sharedInbox。我可以看到未读电子邮件计数和其他计数。

At this point I can check sharedInbox containing the details of the Inbox. I can see the unread email count and others.

但是当我访问

ItemView itemView = new ItemView(100);
FindItemsResults<Item> findResults1 = es.FindItems(pqInbox.Id, itemView);

我遇到异常 SMTP地址没有与之关联的邮箱

I get exception "SMTP address has no mailbox associated with it"

推荐答案

在这种情况下,我的经验是,如果您设置service.UseDefaultCredentials = true,则将登录您的个人计算机。如果您与Exchange Server具有相同的ActiveDirectory结构,则该方法非常理想。如果您尝试从ADS外部连接到交换服务器,则必须手动设置凭据。

my experience in that case is, that if you set service.UseDefaultCredentials = true your Login of your pc will be taken. Which works perfect if your in the same ActiveDirectory structure as the exchangeserver is. If your trying to connect to the exchange server from outside of the ADS you will have to set the credentials manually.

我在使用工具的默认凭据时,我在工作如果我在家中连接,则必须设置凭据。

I'm using the defaultcredentials for my tools when I'm at work. If I connect from at home I have to set the credentials.

希望对您有帮助...

Hope that helps you...

这篇关于Exchange Web服务:UseDefaultCredentials属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆