1

I'm trying to develop a application for syncing calendars & contacts to another system. The application is written in C#, but I don't understand how I can get all user's calendars and contacts, without knowing each one's credentials. The application shouldn't poll the information, but send it to my application like an event.

I already searched on MS sites, downloaded the 'Exchange 2013 101 Code Samples' ans successfully wrote a script which sends an e-mail to another user, but the authentification only worked with user credentials.

Is it possible to create a 'master' user who can read all calendars and contacts of a given list of users? Can ExchangeServer call my application and send the information (e.g. with SOAP), or do I have to poll?


UPDATE:

I created a user who has full permission on everything, but I don't know how to read the data from the server, because the calendar of the 'master' user is empty. When I visit OWA and choose to take an impersonate look into someone's calendar I can see the appointments.

Code for permissions:

Get-Mailboxdatabase | Add-ADPermission -AccessRights ExtendedRight -ExtendedRights Receive-As, Send-As -User "<SuperAccount>"

And this one shares the calendar:

Add-MailboxFolderPermission –Identity <MailboxFolderId>:\Calendar -AccessRight ReadItems -User <SuperAccount>

How can I get the calendar of a user with my master-user?

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
Pixelmonster
  • 396
  • 7
  • 15

2 Answers2

1

The approach we use is that all users must share their calendars with a 'master' user, with full editing rights. This user has to be created in the domain of the server. Our code logs in to Exchange as that master user, and then it can access all calendars.

Another approach that I have no experience with is Impersonation. Exchange lets you act as an other user. You have to have impersonation rights under Windiows for that.

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
  • I finally solved this issue with Impersonation. It's really simple, but very mighty and I can keep the rest of my code, because it's only one more line. - Big Thanks! – Pixelmonster Jul 05 '13 at 13:43
1

According to Jan Doggen's answer I found the solution in another StackOverflow thread, which can be found here: EWS: Access shared calendars

The answer from Seph was in Visual Basic, but it can be easily converted to C#:

using Microsoft.Exchange.WebServices.Data;

DateTime startTime = new DateTime(2013, 1, 1);
DateTime endTime = new DateTime(2013, 12, 31);

var cal = new FolderId(WellKnownFolderName.Calendar, new Mailbox("other user's email"));
var calendarView = new CalendarView(startTime.Date, endTime.Date.AddDays(1));

foreach (var appointmentItem in service.FindAppointments(cal, calendarView))
{
    Console.WriteLine(appointmentItem.Subject);
}
Community
  • 1
  • 1
Pixelmonster
  • 396
  • 7
  • 15
  • When I try to use this code, I get "The specified folder could not be found in the store." – Paige Watson Jan 10 '14 at 00:00
  • I'm sorry for my late answer. Unfortunately I'm not longer working on this project, because it was only a summer job and I'm a student. Are you using the same version of Exchange Server? WellKnownFolderName.Calendar is a generic Foldername which applies to your server. Are you using the right version of ews-managed-api? Did you choose the right Exchange version in Visual Studio? – Pixelmonster Mar 28 '14 at 22:04
  • NP, I think I got it figured out, although I haven't been working on the project in months. Thanks for the response though. – Paige Watson Apr 16 '14 at 18:58