0

请问你能检查这个脚本吗?我无法让它工作 - 我想用它来向不同的地址发送相同的电子邮件,但带有个性化的问候语。

— 脚本需要将两个文件放在与脚本相同的文件夹中。— “Email Addresses.txt”应包含由回车分隔的电子邮件地址。 —“Email Message.txt”应包含第一行的主题,然后是下面的邮件正文(由回车分隔)。

— 获取应存储支持文件的脚本路径。

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
4

1 回答 1

1
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
于 2013-07-08T02:08:02.070 回答