Hi Everyone.
First-time poster, long-time lurker, but I’m fairly new to Applescript and think it can meet a need. Normally I can search and modify others’ script suggestions to make them work for me, but in this case it’s somewhat of a unique issue (apparently) and can’t track down the script-bits to make it work.
The Goal: I need a script that will send a personalized email to multiple contacts located on a spreadsheet within a certain date range.
Context: When guests register at our non-profit, I need to follow up with a series of emails highlighting our upcoming events, etc, over a span of about a month. After which, they drop from the email list. The first two emails are always the same, but the next four will be constantly updated as our events change throughout the season.
Parameters:
I use Apple mail.app linked to gmail.
A spreadsheet, “guests.numbers” (Excel, Numbers, google sheet, or CSV/TSV ” whatever is simplest to script. The script should preferably not have to open the associated application to find the data on the sheet.). The guest data is in the following format:
[format]| A | B | C | D | E |
| date | firstname | lastname | guestemail | phonenumber |
| | | | | |
| 2016-05-01 | Tony | Stark | ironman@shield.com | 555.5555 |
| 2016-05-08 | Steve | Rogers | america@shield.com | 555.5556 |
| 2016-05-22 | Bruce | Banner | iamincredible@shield.com | 555.5557 |[/format]
A second spreadsheet, “emails.numbers”. This sheet contains the subject lines and body of the email messages themselves. (I prefer to keep the email texts in a separate document so I don’t have to edit the script every time I want to edit the email text. The email data is in the following format:
[format]
| A | B | C | D |
| occasion | recipient | subject | body |
| | | | |
| first | [guestemail] | Hi! | Hi, [firstname], thanks for stopping by! |
| second | [guestemail] | Hello! | Hello, [firstname], we’re here for you! |
| third | [guestemail] | Greetings! | Hi again, [firstname], next week is a great event! |
[/format]
The script will be triggered via a series of staggered iCal alarms. Each ˜stagger’ will reference a different row of content, resulting in a different email sent each week. (Example: The iCal alarm on May 29 will send the “first” email to guests dated 2-4 weeks ago [Tony and Steve]. The iCal alarm on June 5 will send the “second” email to guests dated 2-4 weeks ago [Steve and Bruce]. Etc.)
I have this script as my starting point:
property theSender : "my@email.com"
property theSubject : "The same for every message"
property theSignature : "mySignature"
tell application "Mail"
try
set mySignature to signature theSignature
on error
set mySignature to missing value
end try
end tell
tell application "Microsoft Excel" to set theData to value of used range of active sheet
repeat with aRow in theData
set {theName, address1, address2, address3, address4, postcode, theEmail} to aRow
set mailBody to "Dear " & theName & return & return
set mailBody to mailBody & "Some blurb" & return & return
set mailBody to mailBody & "I'm writing to confirm that the following contact details are correct." & return & return
set mailBody to mailBody & address1 & return
set mailBody to mailBody & address2 & return
set mailBody to mailBody & address3 & return
set mailBody to mailBody & address4 & return & return & "Thank you" & return & return
tell application "Mail"
set newMessage to make new outgoing message with properties {sender:theSender, visible:true, subject:theSubject}
tell newMessage
set content to mailBody
make new to recipient at end of to recipients with properties {address:theEmail}
if mySignature is not missing value then set message signature to theSignature
end tell
-- send newMessage
end tell
end repeat
Which I found here: [http://macscripter.net/viewtopic.php?id=38096]
It almost does what I need, it just needs.
(1) To allow the contact list to be limited to a particular date range
(2) To allow the source of the email text to come from outside the script itself.
(3) To bypass opening Excel/Numbers every time the script runs.
Sorry for the long question! I’ve tried to include only the necessary information. Also, if there are other posts that have solved these issues that I’ve missed, please point them out to me and I’ll be happy to try to work them in.
AppleScript: 2.4
Browser: Safari 601.6.17
Operating System: Mac OS X (10.10)