Last active
December 19, 2023 18:58
-
-
Save youandhubris/9e292822e3db8f91df93234db092906e to your computer and use it in GitHub Desktop.
AppleScript to send e-mail, using Apple's Mail, with multiple recipients, cc, bcc and attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Mail" | |
set theFrom to "" | |
set theTos to {} | |
set theCcs to {} | |
set theBccs to {} | |
set theSubject to "" | |
set theContent to "" | |
set theSignature to "" | |
set theAttachments to {} | |
set theDelay to 1 | |
set theMessage to make new outgoing message with properties {sender:theFrom, subject:theSubject, content:theContent, visible:false} | |
tell theMessage | |
repeat with theTo in theTos | |
make new recipient at end of to recipients with properties {address:theTo} | |
end repeat | |
repeat with theCc in theCcs | |
make new cc recipient at end of cc recipients with properties {address:theCc} | |
end repeat | |
repeat with theBcc in theBccs | |
make new bcc recipient at end of bcc recipients with properties {address:theBcc} | |
end repeat | |
repeat with theAttachment in theAttachments | |
make new attachment with properties {file name:theAttachment as alias} at after last paragraph | |
delay theDelay | |
end repeat | |
end tell | |
# macOS 10.12+ know bug | |
# https://stackoverflow.com/questions/39860859/setting-message-signature-of-outgoing-message-using-applescript | |
# set message signature of theMessage to signature theSignature | |
send theMessage | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am totally new to Applescript and coding in general and I have question:
How can I add attachments? If I add the file path to theAttachments I get an error message telling me that the file path cannot be converted in type alias.
Thanks in advance.