EWS - 代理访问

本文关键字:访问 代理 EWS | 更新日期: 2023-09-27 18:32:16

我正在尝试使用 EWS 访问另一个人的日历。我可以很好地访问自己的日历:

    foreach (Appointment appointment in service.FindItems(
        WellKnownFolderName.Calendar, new ItemView(int.MaxValue)))
    {
        Console.WriteLine(appointment.Subject);
    }
}

但是,当我尝试模拟(即使具有代理访问权限)时,我收到以下代码的未处理异常错误(抱歉,这是完整的代码,但认为它很短可能会有所帮助!有问题的孩子似乎在 foreach 循环中

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Exchange.WebServices.Data;
using Test.ExchangeServices;
 using System.Net;
namespace Test
{
class Program
{
    static void Main(string[] args)
    {
 // Connect to Exchange Web Services
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
    service.Credentials = new WebCredentials("User", "Pass", "Domain");
    service.Url = new Uri("https://EWS/EWS/Exchange.asmx");
    //Impersonate the user who is creating the appiontment request (doesn't work so commented out)
// service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, userEmail);
/Delegate access 
    foreach (Appointment appointment in service.FindItems(
new FolderId(WellKnownFolderName.Calendar, new Mailbox("otheremployee@company.com")), 
new ItemView(10)))
    {
        Console.WriteLine(appointment.Subject);
    }
}

    }
}

如果有帮助,我附上了错误的屏幕截图:

http://i44.tinypic.com/nh1jdi.png

EWS - 代理访问

您需要审阅者访问日历,然后它就可以工作了。 :)