繁体   English   中英

AppleScript处理Mac Mail.app中的传入电子邮件

[英]AppleScript to process incoming emails in Mac Mail.app

实际上,我的问题与相同,答案已经使我非常前进。 (摘要:我希望我的python脚本在具有特定主题的每封传入电子邮件中运行,并从内容中提取数据。)

无论如何,我是AppleScript的完全入门者,无法找到将触发电子邮件的内容作为python脚本参数提供的解决方案。

实际上,我只需要传递电子邮件的html内容。

谁能指出我正确的方向或将一些光带入黑暗? 非常感谢你。

我的AppleScript目前看起来像这样,尽管我的脚本现在应该立即打印电子邮件内容,但是什么也没有发生:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"
            repeat with eachMessage in theMessages
                set theContent to source of eachMessage
                do shell script "python completePathToPyScript.py" & theContent
            end repeat
        end tell
    end perform mail action with messages
end using terms from

然后我的python脚本执行以下测试:

import sys

email_data = str(sys.argv[1])
print email_data

还是我接管数据的方式不正确?

尝试这个。 请注意,您不应使用tell application "Mail" ,因为此事件是由Mail触发的,因此您可以访问Mail提供的所有功能。 在这种情况下,只需要using terms from application "Mail" 您可以通过输入命令 + shift + o并选择“ Mail.app”来找到更多信息。 这将为您显示Mail的字典,并且应该是进一步开发代码的良好起点。 我现在对其进行了修改,使其可以在没有任何特定规则的情况下工作,以解决我过去遇到的一些问题:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            if subject of eachMessage contains "Express222" then
                set theContent to source of eachMessage
                display alert theContent
            end if
        end repeat
    end perform mail action with messages
end using terms from

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM