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) & "" "} 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 -- remove the timezone info from the calendar event -- to make compatable with outlook set toss to false set newEventFileContent to "" set last_line to false repeat with theLine in paragraphs of myEventFileContent if theLine contains "BEGIN:VTIMEZONE" then set toss to true else if theLine contains "END:VTIMEZONE" then set last_line to true set toss to false end if if toss is false then if last_line is true then set last_line to false else set newEventFileContent to newEventFileContent & theLine & cr end if end if end repeat set myEventFileContent to newEventFileContent -- pre-pend mail headers to the event contents set myNewEmailText to ¬ "From: " & theAccountTouse & cr & ¬ "To: " & myrecipient & cr & ¬ "Subject: " & subjectLine & cr & ¬ "MIME-Version: 1.0" & cr & ¬ "Content-Type: text/calendar; method=REQUEST;" & cr & ¬ " charset="utf-8"" & cr & ¬ "Content-Transfer-Encoding: 7bit" & cr & ¬ "Importance: Normal" & cr & cr & ¬ myEventFileContent -- " name="meeting.ics"" & cr & ¬ -- create a random event file name set tempMailName to (random number from 1 to 1000000) & ".ics" set aliasTempMail to "/Users/schaappa/" & 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 as «class utf8» close myEventFileHandle -- use SENDMAIL to send the file with proper headers do shell script "cat " & aliasTempMail & " | sendmail -oi -t " -- delete the temp file do shell script "rm " & aliasTempMail on error errMsg display dialog errMsg end try end send_mail_sbrp