10.3: Enable Windows Outlook users to read iCal invitations

Dec 27, '03 04:16:00PM

Contributed by: CoreyK

After moving to iCal, Mail.app and Address Book in Panther, I've wiped Entourage X from my TiBook (after importing mail, contacts and meetings, that is) and haven't looked back! Actually, that's not entirely true: Why doesn't Outlook for Windows like iCal invitations sent through Mail.app? If you haven't seen it first hand from a co-worker, Outlook displays all the meeting info, but complains that it can't find the event on their calendar, nor are they allowed to Accept/Reject it (all of the buttons are grayed out)!.

It turns out that Outlook needs the following mail header to be included in the E-MAIL that contains the invite, rather than just having a 'meeting.ics' file attached:

content-class: urn:content-classes:calendarmessage
The problem is that Mail.app doesn't allow you to change the mail headers for only selected e-mails; it's either an all or nothing deal (see this hint. It turns out that the e-mail is generated and sent via an AppleScript, which can be modified to use whatever e-mail client you'd like.

So, I've modified it to use the sendmail program bundled with OS X, since you can include whatever headers you like. Below is the new AppleScript that you can drop in.

WARNINGS
ALWAYS ALWAYS ALWAYS make a backup of a file before making modifications to it, or you'll be sorry. This script requires that you have a mail relay running that the SENDMAIL command can use. In my case, I'm using Postfix in Panther.

You can find the AppleScript to modify at /Applications -> iCal.app -> Contents -> Resources -> Mail.scpt (for the uninitiated, you control-click on the iCal icon and select Show Package Contents to get to Contents).

Again my warning: If you've navigated through the Finder, highlight Mail.scpt and hit Command-D right now. If you've gone the Terminal route, type cp Mail.scpt Mail.scpt.bak and hit Return.

The function you have to modify is send_mail_sbrp() -- you can leave all the others alone, so I'm only including the code for this one function. iCal will no longer send invitations through Mail.app, but will still retrieve your e-mail address and name from it (or present you with a list of choices if you have multiples, though if you have multiple e-mail addresses on one account, it will only use the first).


on send_mail_sbrp(subjectLine, messageText, myrecipient, invitationPath)
 set pfile to POSIX file invitationPath
 set myfile to pfile as alias
  
 try
  -- define a carriage return
  set cr to (ASCII character 13) & (ASCII character 10)
    
  -- retrieve the user's name and e-mail
  set listOfAccounts to {}
    
  tell application "Mail"
   repeat with oneAccount in every account
    set listOfAccounts to listOfAccounts & ¬
    {"\"" & (get full name in oneAccount) & "\" <" & ¬
    (get email addresses in oneAccount) & ">"}
   end repeat
  end tell
    
  if ((get length of listOfAccounts) is 1) then
   set theAccountTouse to get first item of listOfAccounts
  else
   set theAccountTouse to ¬
   choose from list listOfAccounts ¬
   default items (get first item of listOfAccounts) ¬
   with prompt ¬
   "Please select which mail account to send the invitation from:" ¬
   without multiple selections allowed and empty selection allowed
  end if
    
  -- open and read the iCal event file to insert into an e-mail
  set myEventFileHandle to ¬
  open for access myfile without write permission
   set myEventFileContent to read myEventFileHandle
  close myEventFileHandle
    
  -- pre-pend mail headers to the event contents
  set myNewEmailText to ¬
  "Subject: " & subjectLine & cr & ¬
  "From: " & theAccountTouse & cr & ¬
  "To: " & myrecipient & cr & ¬
  "content-class: urn:content-classes:calendarmessage" & cr & ¬
  "Content-Type: text/calendar;" & cr & ¬
  "  method=REQUEST;" & cr & ¬
  "  name=\"meeting.ics\"" & cr & ¬
  "Content-Transfer-Encoding: 8bit" & cr & cr & ¬
  myEventFileContent
    
  -- create a random event file name
  set tempMailName to (random number from 1 to 1000000) & ".ics"
  set aliasTempMail to "/tmp/" & tempMailName
    
  -- write the new e-mail to a temp file
  set myEventFileHandle to ¬
  open for access (POSIX file aliasTempMail as string) with write permission
  write myNewEmailText starting at 1 to myEventFileHandle
  close myEventFileHandle
    
  -- use SENDMAIL to send the file with proper headers
  do shell script "sendmail < " & aliasTempMail
    
  -- delete the temp file
  do shell script "rm " & aliasTempMail
  on error errMsg
   display dialog errMsg
 end try
end send_mail_sbrp

Comments (14)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20031128231213827