0

尝试为每个地址发送几封带有特定附件的邮件。每个地址都有自己的附件子文件夹。“抓取附件部分”不起作用,我不确定处理程序是否设置正确:我应该将子文件夹传递给处理程序内部的邮件还是保持原样。这是我的第一个长脚本,所以请不要太苛刻;-)

我在想我更接近工作解决方案,但我仍然没有让它发挥作用。到目前为止,这是我的脚本:

`  with timeout of 600 seconds

-- Liste: Alle Empfänger  

tell application "Contacts"
    set emailList to {}
    set testPersons to every person of group "Test"
    repeat with thisTestPerson in testPersons
        set end of emailList to (value of email of thisTestPerson) as string
    end repeat
end tell


-- Liste fuer die Übergabe alphabetisch sortieren 

set the_list to emailList
set otid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10} -- always a linefeed 
set list_string to (the_list as string)
set new_string to do shell script "echo " & quoted form of list_string & " | sort -f"
set new_list to (paragraphs of new_string)
set AppleScript's text item delimiters to otid

-- Liste: Alle Subfolder 

tell application "Finder"
    set mainfolder to choose folder "select a folder"
    set folderList to {}
    set myFolders to every folder of mainfolder
    repeat with attachFolder from 1 to (count of myFolders)
        set end of folderList to attachFolder as string
    end repeat
end tell

-- Sicherheits-Check

set count1 to count of myFolders
set count2 to count of new_list
if count1 is not equal to count2 then
    display dialog "Houston, we have a problem:" & return & "Die beiden Listen sind nicht gleich lang..." buttons {"ok"} with icon 2
    return
end if
 end timeout

 --handler processfolder(myFiles)

 on processfolder(myFiles)
tell application "Mail"
    activate
    set theAddress to (item i of emailList)
    set theMex to (make new outgoing message at end of outgoing messages with   properties {visible:true, subject:"Subjectheader",   content:"email body"})

    tell content of theMex
        make new attachment with properties {file name:FileList} at after last paragraph

    end tell
    tell theMex
        make new to recipient at end of to recipients with properties {address:theAddress}

    end tell
    send theMex
end tell
end processfolder

-- grab attachments and send mail   

tell application "Finder"
repeat with myFolder from 1 to (count of folderList)
    set FileList to {}
    set myFiles to entire contents of myFolder
    repeat with thisFile in myFiles
        set end of FileList to thisFile as string
    end repeat
    my processfolder(myFiles)
end repeat
 end tell
display dialog (count1 as string) & " Nachrichten verschickt."

end`

我相信处理程序应该可以正常工作。将子文件夹列表与地址列表匹配似乎仍然是一个问题,我不确定我的重复循环“抓取附件和发送邮件”是否有效。重复循环的使用很棘手,我仍在努力解决它。关于我仍然做错了什么的任何快速想法?

感谢您的帮助!我真的很感激这个!马可

4

2 回答 2

1

您必须在处理程序中将变量作为参数传递:

1- (item i of emailList): iemailList未在处理程序中定义。

2- {file name:FileList}:处理程序中未定义FileList ,文件名必须是类型的路径aliasstring,而不是路径列表。

set myFiles to entire contents of myFolder: myfolder变量是一个integerentire contents将包含文件夹和文件,如果文件夹不包含子文件夹, entire contents则无用,使用files of xFolder.

其余的还可以,但包含不必要的行。

这是脚本:

with timeout of 600 seconds
    -- Liste: Alle Empfänger  

    tell application "Contacts"
        set emailList to value of email 1 of every person of group "Test"
    end tell

    -- Liste fuer die Übergabe alphabetisch sortieren 

    set otid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {linefeed}
    do shell script "echo " & (quoted form of (emailList as string)) & " | sort -f"
    set emailList to (paragraphs of the result)
    set AppleScript's text item delimiters to otid


    -- Liste: Alle Subfolder 

    activate
    set mainfolder to choose folder "select a folder"
    tell application "Finder" to set folderList to folders of mainfolder


    -- Sicherheits-Check

    set count1 to count folderList
    if count1 is not equal to (count emailList) then
        display dialog "Houston, we have a problem:" & return & "Die beiden Listen sind nicht gleich lang..." buttons {"ok"} cancel button "ok" with icon 2
    end if
end timeout

-- grab attachments and send mail   

repeat with i from 1 to count1
    try
        tell application "Finder" to set myFiles to (files of entire contents of (item i of folderList)) as alias list
        my processfolder(myFiles, item i of emailList)
    end try -- no error on empty folder
end repeat
display dialog (count1 as string) & " Nachrichten verschickt."


on processfolder(tFiles, theAddress)
    tell application "Mail"
        activate
        tell (make new outgoing message at end of outgoing messages with properties {visible:true, subject:"Subjectheader", content:("email body" & linefeed & " ")})
            make new to recipient at end of to recipients with properties {address:theAddress}
            tell content to repeat with tFile in tFiles
                make new attachment with properties {file name:tFile} at after last paragraph
                make new character with data linefeed at after last paragraph
            end repeat
            send
        end tell
    end tell
end processfolder
于 2012-10-19T20:07:19.030 回答
0

完成了!多亏了你和其他一两个专业人士,我现在有了一个漂亮的批量邮件脚本例程,它使用自动机、bash 行和(主要是)applescript。我将它用于工作申请,但您可以将它用于任何需要使用 Mail、MS Word 和 Excel 中的任何给定联系人列表(或就此而言的通讯簿)进行个性化批量电子邮件的情况。为了完整起见,我将添加所有必要的步骤。使用任何给定的 x 个姓名、电子邮件地址、个人地址列表,您可以生成 x 个子文件夹,其中包含 x 个个性化字母和非个性化文档(谢谢,杰克!添加文档效果很好)。一旦您启动最后一个脚本并选择文件夹,您就可以观看将它们全部发送出去的邮件,按姓名称呼该人并附上正确的个性化信件!它更正了在电子邮件地址中呈现不同的外国名称拼写。它最适用于在“@”之前使用姓氏的电子邮件地址,并且现在可以忽略在姓氏前面设置的名字(即 firstname.lastname@company.com)。非常感谢大家的帮助!这是伟大的团队努力。我一到家就发,我应该把它发在这里和其他相关问题中还是有一个分享论坛?

于 2012-10-24T06:53:47.953 回答