MacTech 文章可能已过时。我能找到的有关该主题的 Apple 页面没有提及有关该处理程序的任何内容,带有下划线,仅带有空格。
前者意味着您的脚本根本不需要处理程序。我已经证实这是真的。以下脚本文件在收到消息时触发,并显示对话框:
display dialog "Hello without handler"
后一页使用以下格式,我也验证过:
using terms from application "Mail"
on perform mail action with messages caughtMessages for rule catchingRule
display dialog "We got one!"
end perform mail action with messages
end using terms from
如果您使用 IMAP,则可以从传入的消息中获取数据。例如:
using terms from application "Mail"
on perform mail action with messages caughtMessages for rule catchingRule
repeat with caughtMessage in caughtMessages
try
set mailSubject to subject of caughtMessage
display dialog mailSubject
on error errorString number errorNumber
display dialog errorString
end try
end repeat
end perform mail action with messages
end using terms from
如果您使用的是 POP,则无法收到传入的消息;你会得到类似Can’t get «class mssg» "Incoming POP Messages" of «class mact» id "LONG-ID". Invalid index. 这样的信息,在这种情况下,你可能会发现the answer to this question 上的 cmets 很有用。
总结是,为了从 POP 帐户的传入邮件中获取数据,必须首先将邮件移动到收件箱以外的文件夹。让规则将邮件移动到您创建的另一个邮箱中,例如“传入分类”,然后让脚本遍历该邮箱中的所有邮件,而不是遍历提供给处理程序的邮件。例如:
using terms from application "Mail"
on perform mail action with messages caughtMessages for rule catchingRule
--for POP messages, the rule must have already moved it into Incoming Triage
set caughtMessages to every message of mailbox "Incoming Triage"
repeat with caughtMessage in caughtMessages
tell caughtMessage
set mailSubject to subject
end tell
display dialog mailSubject
move caughtMessage to mailbox "INBOX" of account 1
end repeat
end perform mail action with messages
end using terms from