Posted on 01-15-2018 09:18 PM
Hello All!
I am looking for some guidance to send a bulk email from a CSV using an Apple Script. I exported a CSV that has a column of oweners and then the value is john doe doe@company.com. My goal is to take this list and send emails to each user with a standard reminder. I have been using this script, but cannot figure our for the life fo me how to adjust the values to read just doe@company.com
-- select the file
-- change this to a direct path if you prefer
set theFile to (choose file with prompt "Select the CSV file")
-- read the file contents:
set f to read theFile
-- break the file into paragraphs (c.f. rows)
repeat with row in (paragraphs of f)
-- parse the row into comma-delimited fields
set fields to parseCSV(row as text)
-- now you have your data:
set recipientAddress to item 1 of fields
set theSubject to item 2 of fields
set theContent to item 3 of fields
set recipientName to item 4 of fields
-- presumably you want to do something more with this data?
tell application "Mail"
set NewMail to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
set message signature of NewMail to signature "OG"
tell NewMail
make new to recipient with properties {name:recipientName, address:recipientAddress}
send
end tell
end tell
end repeat
on parseCSV(theText)
set {od, my text item delimiters} to {my text item delimiters, ","}
set parsedText to text items of theText
set my text item delimiters to od
return parsedText
end parseCSV
Thanks for any help!
Jared
Posted on 01-17-2018 11:45 AM
bump
Posted on 01-17-2018 11:53 AM
Can you give a quick example of how the csv is formatted? That might help someone in figuring out your issue.
Posted on 01-17-2018 12:25 PM
Throwing out a random idea...since you can combine AppleScript and bash scripts together using the osacript command within bash, consider using awk or sed or whatnot to "finesse" a problematic line of text for you and then bring that final result back into AppleScript.
Not actually sure if that would work or what the syntax would be, but in thinking mode right now with this post.
Posted on 01-18-2018 01:16 PM
Thanks for reaching out @mm2270 and @blackholemac. I am new to Apple Scripting so I am trying to edit any sort of script to get something working
. Here is an example of the CSV:
Posted on 01-18-2018 02:16 PM
Try this:
on parseMail(theText) set {od, text item delimiters} to {text item delimiters, "<"} set parsedText to text items of theText set text item delimiters to od return parsedText end parseMail set addr to parseMail("John Doe john@doe.com")
Removal of trailing spaces and trailing '>' is left as an exercise for the student.