tell application "Mail"
(* MAIL APPLICATION VERSION *)
set mailversion to version as string
(* SPECIFY DISPLAY OR SEND OPERATION - if displayForManualSend
is true, then the message is prepared and displayed in a window
for the user to send it. if displayForManualSend is false, then
the message is sent right away.*)
set displayForManualSend to true
(* SPECIFY GENERAL CONTENT OF MESSAGE *)
set bodyvar to return & return & "Test body."
set addrVar to "bogus@apple.com"
set addrNameVar to "Guinea Pig"
(* SPECIFY ATTACHMENTS *)
(* This list of files represents another setting of *)
(* the SendMail scriptstep. *)
(* NOTE: A "mailto" URL does not allow for *)
(* the specifying of attachments... *)
set fileAttachThis to choose file of type "TEXT"
set fileList to {fileAttachThis}
(* DEFINE THE SUBJECT LINE *)
set subjectvar to "Test Message From AppleScript with Attachment!"
(* CREATE THE MESSAGE *)
set composeMessage to (a reference to (make new compose message ¬
at beginning of compose messages))
tell composeMessage
make new to recipient at beginning of to recipients ¬
with properties {address:addrVar, display name:addrNameVar}
set the subject to subjectvar
set the content to bodyvar
tell content
repeat with aFile in fileList
make new text attachment ¬
with properties {file name:aFile} ¬
at before the first word of the ¬
first paragraph
end repeat
end tell
end tell
(* SEND OR DISPLAY THE MESSAGE *)
if displayForManualSend then
set messageEditor to make new message editor ¬
at beginning of message editors
(* the following is a work around for a bug fixed in later
versions of the Mail application that was present in versions
1.0 and 1.1. *)
if mailversion is "1.0" or mailversion is "1.1" then
set compose message of last message editor to composeMessage
else
set compose message of first message editor to composeMessage
end if
else
send composeMessage
end if
end tell
|