I have a need to send the same email to allot of people, but wanted to ensure that they all received it with out it being blocked by group mailing filters. Here is the resulting script.
On trial I sent 40 individual emails in 3min 20 sec with 9 lines of text and a 300k attachment
I plan on using this script to send 1800 emails probably in groups of 450
(*
Multiple Individual Emails
This code has been created/altered by Joe Sheehan & members of Macscripter.net Thank you Mark and Adam.
This code is a descendant from Apple sample code titled "Create new message".
This code has been provided "AS IS" and the responsibility for its operation is yours.
*)
(*
This script creates a new message, including setting sender, subject, recipient,
body, and attachment, to multiple people, one at a time, to ensure the message
is recieved and not blocked by a group mailing filter.
*)
--direct to your plain text file with addresses, and name, tab delimited
set theAddressDOC to read file ("Macintosh HD:Users:user:Desktop:address.txt")
set pcount to count paragraphs in theAddressDOC
repeat with i from 1 to number of paragraphs in theAddressDOC
set this_item to paragraph i of theAddressDOC
set Name_text to "" -- set to blank
-- using try so if there is a an error, in this case it will be when the is no name, the script will carry on
-- instead of stopping. The Name_text will reamin as "" if it does
try
--use delimiters (tab) in this case to split the result of this_item and try to set Name_text to the name
set AppleScript's text item delimiters to tab
set para_text to text of this_item
--get the second half of paragraph
set Name_text to text item 2 of para_text
end try
--get the first half of paragraph
set address_text to text item 1 of para_text
--reset the delimiters
set AppleScript's text item delimiters to ""
set theAddress to address_text
-- direct to a doc of what you want the email to say in plain text
set theletter to read file ("Macintosh HD:Users:user:Desktop:Letter.txt")
-- What is the subject of the Emails
set theSubject to "Example"
-- Check to see if Name_text contains a name or not
if Name_text is "" then
--if no name
set theBody to "To whom it may concern" & theletter
else
--the must be a name
set theBody to "Hello " & Name_text & theletter
end if
theBody
-- add atachment. you need to set the full path.
-- If no attachment remove this line and the "make new attachment" line further down
set theAttachment to alias "Macintosh HD:Users:user:Desktop:Attachment"
-- Choose the account to send the message from
set theSender to "123@example.com"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
tell newMessage
-- Default is false. Determines whether the compose window will
-- show on the screen or whether it will happen in the background.
set visible to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
tell content
-- Position must be specified for attachments
make new attachment with properties {file name:theAttachment} at after the last paragraph
tell application "Mail"
send newMessage
end tell
-- delay to allow the Mail program to send and not bog down, adjust as needed
delay 4
end tell
end tell
end tell
end repeat