0

Found a script to create bulk e-mail distribution:

    on run {input, parameters}

        set addresses to "aa@example.com
        bb@example.com"
        set names to "Ann
Bob"
        set title to "title"
        set theAttachmentFile to "SSD:Users:me:file.pdf"
        set body1 to "Hello "
        set body2 to ",

This is a test message"

        repeat with a in paragraphs of addresses
            tell application "Mail"
                activate
                tell (make new outgoing message)
                    set visible to true
                    make new recipient at end of to recipients with properties {address:a}
                    set subject to title
                    -- set salutation to ???
                    set body to body1 & salutation & body2

                    set content to body
                    --save
                    --send
                end tell
            end tell
        end repeat

        return input
    end run

Adding attachment as advised by user3439894 with:

tell content to make new attachment with properties {file name:theAttachmentFile as alias} at after last paragraph

How do I add name into body for each recipient (marked with ???)?

  • At the moment I'm not where I can test this, hence the comment and not posting an answer however, directly after set content to body, on the next line, try using: tell content to make new attachment with properties {file name:theAttachmentFile as alias} at after last paragraph – user3439894 Jan 11 at 13:34
  • Thank you user3439894. Your proposition is to add before actual creation of e-mails and they do not exist at that time. Tried your code, not working - Variable content is not defined. – Pavel Jan 11 at 13:38
  • Moved your code after save, everything works, but I get an error File /Users/me/file.pdf wasn’t found Should I convert it to Macintosh HDD:Users:me:file.pdf? – Pavel Jan 11 at 13:46
  • And the answer is YES - use semicolon delimited path! SOLVED – Pavel Jan 11 at 13:50
  • Why are you setting addresses and names to paragraphs of ... instead of using a list object, e.g. set addresses to {"aa@example.com", "bb@example.com"} and set names to {"Ann", "Bob"}, then assuming the lists are the same count and in the proper corresponding order... this way you can index through the two lists so i.e. item i of names corresponds to item i of addresses e.g. repeat with i from 1 to (count addresses) then {address:a} becomes {address:item i of addresses} and -- set salutation to ??? becomes: set salutation to item i of names – user3439894 Jan 11 at 15:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.