Mac – Attach unique attachment to email using apple script to send email to different users


I'm new to apple script:

Does anyone have an example of using an AppleScript to send individual emails with unique attachments for each email using an excel list? (Lots of examples out there sending emails with an attachment, but no one seems to have done it with different attachments for each mail???)

I have an email list in excel which holds all email addresses and file names


a Folder with each excel file in it.

I want to send the email to user in email list and attach file to email and on a loop until complete. Each person should receive the same email but will have different file attached.

Can someone provide example please?

Best Answer

set theWorkbookFile to choose file with prompt "Please select an Excel workbook file:" set theWorkbookName to name of (info for theWorkbookFile) tell application "Microsoft Excel" open theWorkbookFile set theWorkbook to workbook theWorkbookName set peremail to value of used range of active sheet end tell

--This is the part that I am stuck on???--

tell application "Finder" activate set theAttachmentFile to every file of "Macintosh HD:Users:j:Box:Email test:"whose name contains (peremail as Unicode text) -- the attachment path end tell

repeat with aRow in peremail set {theEmail, theName} to aRow tell application "Mail" set newMessage to make new outgoing message with properties {sender:thesender, subject:"Order"} tell newMessage set content to "XXXX" make new to recipient at end of to recipients with properties {name:theName, address:theEmail} tell content of newMessage

            make new attachment with properties {file name:theAttachmentFile as alias} at after the last word of the last paragraph
        end tell
        delay 3
    end tell
end tell

end repeat