33.1 Setting Up an Email Message
The
easiest way for a script to get Mail started on a new email message
(but not actually complete and send the message) is to use the
GetURL command. This command takes as its
parameter a string "mailto" URL,
which looks like
mailto:bwperry@parkerriver.com?subject=My%20mail.
Mail responds to this command by opening up a new message window and
constructing the email according to the string parameter you used
with GetURL. The result might look like Figure 33-2. Notice that the string parameter itself must
be URL-encoded (e.g., %20 symbols replacing any space characters) for
the message to be properly constructed.
The new email message window becomes the active Mail window and the
frontmost window on the desktop if you use the
activate command, as in Example 33-1. Mail includes a send
command in its dictionary, for sending the mail.
Example 33-1. Using Mail's GetURL Command
set theAdd to text returned of (display dialog "enter the recipient's
email address please:" default answer "")
set subj to "scripted%20mail"
set cont to "AppleScript%20sent%20this%20mail."
tell application "Mail"
activate
GetURL ("mailto:" & theAdd & "?subject=" & subj & "&body=" & cont)
end tell
|