Skip to content

Instantly share code, notes, and snippets.

@michaelengel
Last active December 8, 2023 22:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelengel/f366ec8fe5312ef4129c0c2e99aa818c to your computer and use it in GitHub Desktop.
Save michaelengel/f366ec8fe5312ef4129c0c2e99aa818c to your computer and use it in GitHub Desktop.
AppleScript to send Email using Mail.app to multiple recipients from Contacts.app
tell application "Contacts"
repeat with i in people of group "Recipients" # Replace with name of group
tell application "Contacts" to get the value of emails of i
set addr to the value of emails of i
# Salutation is stored in the "nickname" field
set salut to the nickname of i
# Language is stored in the "note" field - E = English
set english to the note of i
tell application "Mail"
set theFrom to "sender@domain.com"
set theTos to addr
# The standard encoding for files read here is Western (Mac OS Roman)!
if english is not "E" then
set theSubject to "Foreign Language Subject"
set theContent to salut & (read POSIX file "/path/to/ForeignLanguageBody.txt")
else
set theSubject to "English Subject"
set theContent to salut & (read POSIX file "/path/to/EnglishBody.txt")
end if
set theSignature to ""
set theAttachments to {"/path/to/attchment.pdf"}
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 theAttachment in theAttachments
make new attachment with properties {file name:theAttachment} at after last paragraph
delay theDelay
end repeat
end tell
# macOS 10.12+ known bug
# https://stackoverflow.com/questions/39860859/setting-message-signature-of-outgoing-message-using-applescript
# set message signature of theMessage to signature theSignature
# If you don't send the message here, they will appear in the Drafts folder
# so you can review each message before sending
# send theMessage
end tell
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment