Verwenden von AppleScript zum Senden von E-Mails von Mail.app an mehrere Adressen

Ich kann erfolgreich eine E-Mail mit Anhang an eine einzelne E-Mail-Adresse senden, indem ich den folgenden Code verwende:

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

    tell application "Mail"

        set theAddress to "recipient1@domain.com" -- 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

Ich kann jedoch nicht herausfinden, wie ich diesen Code ändern kann, um die E-Mail sowohl an Empfänger1@Domäne.com als auch an Empfänger2@Domäne.com zu senden. Weiß jemand wie ich vorgehen würde? Ich bin sehr neu bei AppleScript, also würde ich die Hilfe sehr schätzen!

Antworten (2)

Ich konnte die set theAddressZeile und die tell msg to make new to recipientZeile optimieren, damit der folgende Code wie beabsichtigt ausgeführt wird:

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

    tell application "Mail"

        set theAddress to {"recipient1@domain.com","recipient2@domain.com"} 
        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
Denken Sie, dass es möglich ist, die Liste der E-Mail-Adressen aus einer TXT-Datei festzulegen?

Ja. Es ist möglich, 1 E-Mail-Adresse pro Zeile anzunehmen:

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