[英]Exchange Web Services - accessing calendar of group mailbox using service account
I am trying to access a group mailbox using the Exchange Web Services. 我正在尝试使用Exchange Web服务访问组邮箱。
A domain account with full access to the group mailbox has been setup, but I am getting the following error: 已设置对组邮箱具有完全访问权限的域帐户,但是出现以下错误:
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.
My code is below: 我的代码如下:
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);
Is there any way of achieving this without setting up a mailbox for the service account? 有什么方法可以在不为服务帐户设置邮箱的情况下实现?
When I run the above code with my credentials, there are no issues (I have full permission to the group mailbox, and a mailbox of my own). 使用凭据运行上述代码时,没有任何问题(我对组邮箱和我自己的邮箱拥有完全权限)。
Use impersonation . 使用模拟 。 This code works great for me to connect to a shared mailbox as a service account.
此代码对我来说非常有用,可以将其作为服务帐户连接到共享邮箱。
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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.