在Mavericks中通过邮件规则处理Applescript中的传入消息

时间:2014-09-21 22:48:53

标签: email applescript rule

我有一个简单的自动回复脚本,基于我在此处和其他地方看到的示例,旨在从垃圾邮件过滤邮件规则运行。以下是它的要点:

on perform_mail_action(theData)
    tell application "Mail"
        set theMessages to |selectedMessages| of theData
        repeat with theIncomingMessage in theMessages
            set theOriginalSender to sender of theIncomingMessage
            set theOriginalSubject to subject of theIncomingMessage
            set theOriginalContent to content of theIncomingMessage
            set t to ""
            set t to t & "This is an automated response to your message below..."
            set t to t & return & return & "===============================================" & return & return
            set t to t & "Subject:" & theOriginalSubject & return & return & theOriginalContent
            set theReply to make new outgoing message
            tell theReply
                make new to recipient at beginning of to recipients ¬
                    with properties {address:theOriginalSender}
                set sender to "xxx@xxx.net"
                set subject to "RE: your message"
                set content to t
                send
            end tell
            set mailbox of theIncomingMessage to mailbox "Trash"
        end repeat
    end tell
end perform_mail_action

我知道调用此脚本的规则正在触发,因为它会播放声音。但没有发送任何内容,收到的消息仍保留在我的收件箱中。

如果我删除第一行和最后一行,并用

替换第三行
    set theMessages to messages of mailbox "test" of account "iCloud"

然后它成功处理" test"中的所有消息。文件夹(它发送回复并删除传入的消息)。

该规则除了播放声音并调用脚本外什么都不做。如上所述,声音播放。我错过了什么?

2 个答案:

答案 0 :(得分:0)

将前3行(包括set theMessage...)替换为:

using terms from application "Mail"
   on perform mail action with messages theMessages for rule theRule
      tell application "Mail"

将最后一行替换为:

   end perform mail action with messages
end using terms from

答案 1 :(得分:0)

尽管网上有可用信息(例如Introduction to Scripting Mail),但为了详细说明Michele Percich的回复,邮件似乎没有运行以下形式的处理程序:

on perform_mail_action(theData)

但是,如果以这种形式编写,它将运行处理程序:

using terms from application "Mail"
   on perform mail action with messages theSelectedMessages for rule theRule
相关问题