【问题标题】:can i add several attachments from subfolders to Mail?我可以将多个附件从子文件夹添加到邮件吗?
【发布时间】:2012-10-09 22:44:29
【问题描述】:

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

我认为我更接近工作解决方案,但我仍然无法使其发挥作用。到目前为止,这是我的脚本:

`  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`

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

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

【问题讨论】:

    标签: applescript email-attachments apple-mail


    【解决方案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 无用,请使用 @ 987654331@.

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

    这是脚本:

    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
    

    【讨论】:

    • 杰克,效果很好!我会试着理解我做错了什么。非常感谢您的帮助!如果您有任何关于如何更好地理解不同类之间的联系以及使用文件和文件夹的好资料,您能告诉我吗?我已经浏览了数周,大多数初学者脚本都专注于处理简单的数字和文本,但没有执行如何解释处理现实世界情况的上下文的步骤。再次感谢!!!!
    • 来源macscripter.netApplescript FAQ,转到页面底部(10个链接,每个链接包含几个主题)。如果您是编程初学者,我建议您购买一本有关 AppleScript 的书 (macstuff.beachdogs.org/blog/?page_id=58)。通常,我们会从我们在第一个脚本中犯的错误中吸取教训。因此,您编写的脚本越多,您学到的就越多。请耐心等待。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2014-08-25
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      相关资源
      最近更新 更多