7

I can ignore the braying of my users no longer. They want a task scheduling system and at some point I have to deliver. I was thinking of making my own (can't be hard), but then users would have two side-by-side task managements systems since they already use Outlook for the same thing.

In terms of Outlook calendar / task integration, two possible approaches occurred to me:

1) Use JavaScript and Automation

I seem to remember it's possible to do automation in JavaScript.

PROS:

  • I've done automation before.

CONS:

  • Automation is horrible!
  • Some persistence (Outlook entities) is the responsibility of client-side code, and the rest the responsibility of server-side code. This feels horrible.
  • Possible security concerns /
    blocking from IT dept.

2) Use some .NET API to interact with Exchange Server directly

The intranet uses single-sign on, so hopefully that should make security issues easier.

PROS:

  • All persistence code would be server-side.

CONS:

  • I don't even know that such an API exists.

As ever, I like to stand on the shoulders of giants. Can anyone who has trodden this path before give me some guidance?

Alfred Myers
  • 6,384
  • 1
  • 40
  • 68
David
  • 15,750
  • 22
  • 90
  • 150
  • I'm guessing with JavaScript Automation you mean JScript (Windows Scripting Host) and OLE? If so, that probably won't work in a browser and requires Outlook to be installed on the computers so that OLE is available. – Nelson Rothermel Dec 01 '10 at 20:54
  • I just recall that many years ago I was able to get JavaScript to do basic automation of (I think) Word. Yes, Outlook would have to be installed on the computer, but it's the user's computer, so it would be. – David Dec 01 '10 at 22:16

2 Answers2

7

We recently did same kind of integration for our intranet application using the Exchange Web Services Managed API. That would be one way of going about for the second option. I have never tried the same using JavaScript, so no idea on that.

With regards to the query for comment 1: You would need a single AD user whom you will be using to impersonate and work on the other users account. Please refer to the example below:

Lets say I have an Active Dir account named fabrikam\myappname with password Fabi$Gre@t2010

void CreateFolder(string targetUserEmail) {
    string appName = "myappname";
    string appPassword = "Fabi$Gre@t2010";
    string emailDomain = "fabrikam";
    string appEmail = string.Format("{0}@{1}.com", appName, emailDomain);

    ExchangeService service = new ExchangeService();
    service.Credentials = new NetworkCredential(appName, appPassword, emailDomain);
    service.AutodiscoverUrl(appEmail);

    service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, targetUserEmail);

    Folder newFolder = new Folder(service);
    newFolder.DisplayName = "TestFolder1";

    newFolder.Save(WellKnownFolderName.Inbox);
}

Do check the article Configuring Exchange Impersonation to make Impersonation working.

Hope that helps.

Nathan
  • 1,675
  • 17
  • 25
  • This looks perfect. If you don't mind me pumping you further, what do I need to know about Joe Bloggs before I can start using the API to add stuff to his calendar? Do I need his Active Directory password (this would obviously be highly problematic). Also, will the API allow me as a developer to see calendar info for anyone? Or can I (or the IT people) configure 'levels' of access? I'm just thinking how hard it would be to persuade company bosses I need this tool if it also means I can read their calendars and emails. – David Dec 01 '10 at 22:26
  • @David: Updated my answer based on your comment. –  Dec 02 '10 at 05:41
  • Thank you CC, that is immensely helpful. – David Dec 02 '10 at 09:02
0

If for some reason you don't want to enable impersonation (since it's global) you can also have each user share their calendar with your profile that is running the app (appName in CodeCanvas' sample). Once they give your the appropriate permission (read/write/edit) you can add appointments to their calendar like so:

myappointment = new Appointment(service);
myappointment.Subject = "subject";
myappointment.Body = "body";
myappointment.Start = myStartTime;
myappointment.End = myStartTime.AddHours(1);
myMailbox = new Mailbox("username@domain.com");
myFolder = new FolderId(WellKnownFolderName.Calendar, myMailbox);
myappointment.Save(myFolder, SendInvitationsMode.SendToNone);
/* get the appointment id so your app can access it later to update or delete */ 
myexchangeid = myappointment.Id.UniqueId;
Tony
  • 818
  • 1
  • 7
  • 21