【问题标题】:Exchange Web Services - accessing calendar of group mailbox using service accountExchange Web 服务 - 使用服务帐户访问组邮箱的日历
【发布时间】:2016-02-08 12:17:59
【问题描述】:

我正在尝试使用 Exchange Web 服务访问组邮箱。

已设置对组邮箱具有完全访问权限的域帐户,但我收到以下错误:

When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids.

我的代码如下:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);

service.UseDefaultCredentials = false;
service.Credentials = new WebCredentials("ServiceAccount", "<PASSWORD>");

//find web service url
service.AutodiscoverUrl("<GROUP MAILBOX EMAIL ADDRESS>", RedirectionUrlValidationCallback);

//find calendar ID
FolderId folderID = new FolderId(WellKnownFolderName.Calendar, new Mailbox("<GROUP MAILBOX EMAIL ADDRESS>"));

//find calendar
CalendarFolder calendar = CalendarFolder.Bind(service, folderID);

//create CalendarView
CalendarView view = null;

var propertySet = new PropertySet(
    AppointmentSchema.Id,
    AppointmentSchema.Subject,
    AppointmentSchema.Start,
    AppointmentSchema.End
);

view = new CalendarView(DateTime.Now.AddMonths(-1), DateTime.Now.AddMonths(1));
view.PropertySet = propertySet;

//get appointments
var appointments = calendar.FindAppointments(view);

有没有办法在不为服务帐户设置邮箱的情况下实现这一点?

当我使用我的凭据运行上述代码时,没有任何问题(我对组邮箱和我自己的邮箱拥有完全权限)。

【问题讨论】:

    标签: c# exchangewebservices


    【解决方案1】:

    使用impersonation。此代码非常适合我作为服务帐户连接到共享邮箱。

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
    service.Credentials = new NetworkCredential(service_acct, password);
    
    // Set impersonation to the shared mailbox
    service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "sharedmbx@contoso.com");
    

    【讨论】:

    • 使用模拟时,我收到以下错误:The SMTP address has no mailbox associated with it.
    • 确保您的服务帐户使用 ApplicationImpersonation 角色 (msdn.microsoft.com/EN-US/library/office/…) 正确配置并允许模拟组邮箱。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多