Scripting Apple Mail
Hey Folks,
This keeps coming up over and over, so I'm giving it a topic of its own.
01) How to create a new outgoing message with one or more attachments.
-------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2013/05/15 06:11
# dMod: 2017/02/04 19:15
# Appl: Apple Mail
# Task: Make a new outgoing message with attachments example.
# Libs: None
# Osax: None
# Tags: @Applescript, @Mail, @Create, @Make, @New, @Outgoing, @Message, @Attachments
-------------------------------------------------------------------------
# The attachment list MUST be made up of a LIST of file aliases!!!!
set attachmentList to {alias "Mercury:Users:chris:test_directory:Mail_Attachment_Test:Test_Archive_01.zip", alias "Mercury:Users:chris:test_directory:Mail_Attachment_Test:Test_Archive_02.zip", alias "Mercury:Users:chris:test_directory:Mail_Attachment_Test:Test_Archive_03.zip"}
set toName to "Robert A. Heinlein"
set toAddress to "bob@pieinthesky.com"
set msgSender to "Your Name <YourEmailAddress@YourDomain.com>"
set msgSubject to "Example Message with Attachments"
set msgBody to "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal."
tell application "Mail"
set newMsg to make new outgoing message with properties {subject:msgSubject, content:msgBody & return & return}
tell newMsg
set visible to true
make new to recipient at end of to recipients with properties {name:toName, address:toAddress}
set sender to msgSender
repeat with theAttachment in attachmentList
make new attachment with properties {file name:theAttachment} at after the last paragraph
end repeat
end tell
end tell
--------------------------------------------------------------------------
NOTE – If you don't understand what an alias is or how to make one stay tuned – I will post a tool for making them soon.
-Chris