Skip to content

Instantly share code, notes, and snippets.

@youandhubris
Last active December 19, 2023 18:58
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save youandhubris/9e292822e3db8f91df93234db092906e to your computer and use it in GitHub Desktop.
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
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
@gh-isoar
Copy link

theDelay is in seconds? milliseconds? thanks!

Seconds. And to be clear, the delay is to provide time for attaching an attachment to complete. So, if attaching a list of attachments is unstable, trying increasing the delay.

@Timbone53
Copy link

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.

@fabiofidanza
Copy link

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment