我有一个要求,比如我需要使用Exchange服务API中的管理员帐户来获取所有用户日历事件。我试过但我无法实现它,所以请告诉我这个。 PFB代码供您参考。我使用的是Exchange服务器版本2013_SP1。在下面的代码中,我只能获得一个用户日历事件详细信息。
public List<EWSModel> GetCalendarEventDetails()
{
List<EWSModel> objCalItems = new List<EWSModel>();
try
{
ExchangeService service = CallEWSAPIService();
DateTime startDate = DateTime.Now.AddDays(-30);
DateTime endDate = DateTime.Now;
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
CalendarView cView = new CalendarView(startDate, endDate);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
EWSModel objModel = null;
foreach (Appointment appItem in appointments)
{
appItem.Load();
List<string> attendees = new List<string>();
foreach (var emailItem in appItem.RequiredAttendees)
{
attendees.Add(emailItem.Name);
}
objModel = new EWSModel();
objModel.AppointmentTitle = appItem.Subject.ToString();
objModel.Subject = appItem.Subject.ToString();
objModel.Body = StripHTML(appItem.Body.Text).Replace("\r", "").Replace("\n", "");
objModel.EmailAddress = attendees;
objModel.Location = appItem.Location.ToString();
objModel.StartDate = appItem.Start;
objModel.EndDate = appItem.End;
objCalItems.Add(objModel);
}
}
catch (Exception err)
{
throw err;
}
return objCalItems;
}
答案 0 :(得分:1)
我自己找到了答案。使用模拟技术,将满足要求。首先,启用对Exchange的Admin用户的模拟访问。请参阅以下link来执行此操作。然后,从您的代码中,您可以为任何用户设置模拟(使用管理员用户)以访问该用户的日历详细信息(交换),使用以下代码进行参考
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new WebCredentials(username, password);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, [username whose detail is needed]);
有关详细信息,请参阅以下link。
答案 1 :(得分:0)
首先要考虑的是,作为管理员不会授予您对其他用户邮箱的任何权限,因此如果您想要访问其他用户,则需要使用Add-MailboxPermissions专门授予管理员访问该邮箱的邮箱。一旦您授予访问权限(并等待该更改生效),您可以使用FolderId重载,例如
FolderId CalendarFolderId = new FolderId(WellKnownFolderName.Calendar,"MaiiboxtoAcces@domain.com");
CalendarFolder calendar = CalendarFolder.Bind(service, CalendarFolderId, new PropertySet(BasePropertySet.FirstClassProperties));
另一个选项是授予管理员帐户模拟您要访问的用户的权限,请参阅https://msdn.microsoft.com/en-us/library/bb204095(EXCHG.140).aspx和https://msdn.microsoft.com/en-us/library/office/dd633680(v=exchg.80).aspx
干杯 格伦