How to automate sending emails with AppleScript

For anyone searching for a solution, below is an AppleScript that can automatically send emails from AppleMail from a list in Numbers. There is a caveat: if it is a long list your internet service provider may limit the number of emails you send in a day and can lock up your email account.


-- This script pulls a first name and an email address from Numbers and sends each email from the Apple Mail client one at a time


-- This is the static text that will be used for all email body text

set LocContent to "


This is the first sentance


This is the second sentance and I have a lot to say. Howdy! Stately, plump Buck Mulligan came from the stairhead bearing a bowl of lather on which a mirror and a razor lay crossed. A yellow dressing gown, ungirdled, was sustained gently behind him on the mild morning air. He held the bowl alof and intoned 'Introibo ad altare Dei.'


This is the last paragraph. HeHo! Yours in Liberty.

"



tell application "Numbers"


-- In Numbers the first table is Table 1. It is hard to know this because the table most likely does not have its name appear, but the active sheet in a new Number file is Table 1. There can be multiple tables on a sheet. Therefore you need to designate the document (file) sheet, and table before you can access attributes

tell table 1 of active sheet of front document


-- For each row for the count of cells in the first column

repeat with i from 1 to count of cells of column 1


-- Get the values of the Name and Address for each row and store locally

set LocName to value of cell i of column "A"

set LocAddress to value of cell i of column "B"


tell application "Mail"


-- Create new email message

set MyMessage to make new outgoing message


-- Set the attributes of the email

set subject of MyMessage to "This is the subject of the email"

-- Append the first name from Numbers to the salutation

set content of MyMessage to "Dear " & LocName & "," & LocContent

set sender of MyMessage to "MyEmail@email.gom"


tell MyMessage

-- New email message to each recipient email address

make new to recipient at end of to recipients with properties {address:LocAddress}

-- Attache the image file as the signature

make new attachment with properties {file name:"/Users/Me/Documents/signature.png"}

end tell


-- Make sure there is time to read the image attachment and attach it before sending

delay 1


-- All information is set, send the message

send MyMessage


-- Make sure the mail client is able to beffer by delaying until the next send

delay 10


end tell


end repeat


end tell


end tell

MacBook Pro, OS X Mavericks (10.9), 2.2 gHz Intel Core i7, 16GB RAM

Posted on Sep 13, 2018 6:39 PM

Reply

Similar questions

1 reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to automate sending emails with AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.