質問

Please can you check this script? I can not get it to work - I would like to use this to send the same e-mail to different addresses but with a personalised greeting.

— Script requires two files placed in the same folder as the script. — “Email Addresses.txt" should contain email addresses separated by a carriage return. — “Email Message.txt" should contain the Subject on the first line then the message body below (seperated by a carriage return).

— Get path to script where the support files should be stored.

set myPath to (path to me) as text
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set textChunks to text items of myPath
if last item of textChunks is "" then set textChunks to _chopLast(tectChunks)
set myFolderPath to _chopLast(textChunks) as text
set AppleScript's text item delimiters to oldDelims
log myPath
log myFolderPath

tell application "Finder"
    -- Get the list of recipients
    set recFile to (myFolderPath & ":Email Addresses.txt")
    set recList to ""
    set recFileID to (open for access (recFile as alias))
    -- Extract text from the file
    try
        set fileLength to (get eof recFileID)
        set recList to (read file recFile from 1 to (fileLength))
    on error error_message number error_number
        display alert "Error number: " & (error_number as string) & return ¬
            & ("Message: ") & error_message
        close access recFileID
    end try
    log recList
    -- Get the email subject and body
    set msgFile to (myFolderPath & ":Email Message.txt")
    set msgFileID to (open for access (msgFile as alias))
    -- Extract text from the file
    try
        set fileLength to (get eof msgFileID)
        set emailBody to (read file msgFile from 1 to (fileLength))
    on error error_message number error_number
        display alert "Error number: " & (error_number as string) & return ¬
            & ("Message: ") & error_message
        close access msgFileID
    end try
    log emailBody
    -- Seperate Subject from Body
    set emailSubject to the first paragraph of emailBody
    log emailSubject
    set emailMsg to paragraphs 2 thru (count of paragraphs in emailBody) of emailBody
    log emailMsg
    set recListList to paragraphs in recList
    -- Loop for each address.
    repeat with eachAddress in (recListList)
        set txtURL to ("mailto:" & eachAddress & "?subject=" & emailSubject & "&body=" & emailMsg as string)
        open location txtURL
        tell application "Mail"
            activate
            -- Uncomment the following line if you want to automatically send messages
            -- send newMessage
        end tell
    end repeat
end tell

on _chopLast(theList)
    return reverse of (rest of (reverse of theList))
end _chopLast
役に立ちましたか?

解決

set addresses to "aa@example.com
bb@example.com"
set title to "title"
set body to "body"
--set body to read "/Users/username/Documents/body.txt" as «class utf8»

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 content to body
            --send
        end tell
    end tell
end repeat
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top