2

I am able to successfully send out an email with an attachment to a single email address using the code below:

on run argv
    set theSubject to (item 1 of argv)
    set theAttachmentFile to (item 2 of argv)

    tell application "Mail"

        set theAddress to "[email protected]" -- the receiver 
        set theSignatureName to "Sig" -- the signature name 

        set msg to make new outgoing message with properties {subject:theSubject, visible:true}

        tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
        tell msg to make new attachment with properties {file name:theAttachmentFile as alias}

        set message signature of msg to signature theSignatureName

        send msg
    end tell
end run

However, I can't figure out how to change this code to send the email to both [email protected] and [email protected]. Does anyone know how I would go about doing so? I'm very new to AppleScript, so I'd greatly appreciate the help!

0

2 Answers 2

5

I was able to tweak the set theAddress line and the tell msg to make new to recipient line to make the following code run as intended:

on run argv
    set theSubject to (item 1 of argv)
    set theAttachmentFile to (item 2 of argv)

    tell application "Mail"

        set theAddress to {"[email protected]","[email protected]"} 
        set theSignatureName to "Sig" -- the signature name 

        set msg to make new outgoing message with properties {subject:theSubject, visible:true}

        tell msg
            repeat with i from 1 to count theAddress
                make new to recipient at end of every to recipient with properties {address:item i of theAddress}
            end repeat
        end tell
        tell msg to make new attachment with properties {file name:theAttachmentFile as alias}

        set message signature of msg to signature theSignatureName

        send msg
    end tell
end run
1
  • 1
    Do you think that it is possible to set the list of email addresses from a txt file?
    – Nicholas
    Mar 29, 2017 at 8:08
-1

Yes. It's possible assuming 1 email address per line:

set srcFile to ((path to desktop) as text) & "myFile.txt"


set theAddresses to paragraphs of (read file srcFile as «class utf8»)


repeat with theAddress in theAddresses
 # ... insert code to create and send email to each recipient "theAddress" is each email address
end repeat

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .