Exchange Web服务托管API:访问其他用户项

时间:2010-09-24 12:35:21

标签: c# web-services exchange-server exchangewebservices ews-managed-api

是否可以访问除登录用户之外的其他Exchange帐户的文件夹和项目?

我可以通过Exchange Web服务托管API执行此操作吗?

3 个答案:

答案 0 :(得分:15)

是的,这是可能的,但您应该知道其他用户的密码或以某种方式获取此凭据(NetworkCredential对象)。代码的典型第一行可能是

ExchangeService myService = new ExchangeService (ExchangeVersion.Exchange2007_SP1);
myService.Credentials = new NetworkCredential ("user@mycorp.local", "P@ssword00");

这样您就可以使用其他作为当前用户的帐户访问Exchange Server Web服务。有关详细信息,请参阅ExchangeService object说明。

如果您是管理员,则可以设置用户impersonation by SMTP address

答案 1 :(得分:4)

知道密码错误并且使用模拟(这些天)是错误的。

这是你如何做到的。

        ExchangeService _service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        //CREDENTIALS OF AN ACCOUNT WHICH HAS READ ACCESS TO THE CALENDAR YOU NEED
        _service.Credentials = new WebCredentials(username, password);
        _service.Url = new Uri(serviceURL);

        SearchFilter.SearchFilterCollection searchFilter = new SearchFilter.SearchFilterCollection();
        searchFilter.Add(new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, DateTime.Now.AddDays(-1)));
        searchFilter.Add(new SearchFilter.IsLessThanOrEqualTo(AppointmentSchema.Start, DateTime.Now.AddDays(2)));
        ItemView view = new ItemView(50);
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.AppointmentType, AppointmentSchema.End);

        //THIS NEXT LINE!!!
        var calendarSearch = new FolderId(WellKnownFolderName.Calendar, new Mailbox("email@ofsomemailbox.com"));
        var appointments = _service.FindItems(calendarSearch, searchFilter, view);

答案 2 :(得分:0)

我建议使用模拟而不是每个用户登录。 通过模拟,您可以冒充用户。它与完全访问权限不同。完全访问是表现的,模仿就是充当。

模仿的前提是你有一个用户名和密码,而不是x用户名和密码。

您可以像这样使用模拟:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new NetworkCredential(appName, appPassword, emailDomain);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, userToImpersonate);

当用户具有对其他人的委托访问权限时,您可以访问其他用户的文件夹。例如:人员A将被模拟并且能够访问人员B