【问题标题】:AppleScript to process incoming emails in Mac Mail.appAppleScript 在 Mac Mail.app 中处理传入的电子邮件
【发布时间】:2015-06-30 06:43:45
【问题描述】:

其实我的问题和this one 是一样的,而且答案已经让我进步了很多。 (总结:我希望我的 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

或者我接管数据的方式不正确?

【问题讨论】:

  • 你试过的代码在哪里?

标签: python macos email applescript


【解决方案1】:

试试这个。请注意,您不应使用tell application "Mail",因为此事件由 Mail 触发,因此您可以访问 Mail 提供的所有功能。在这种情况下,您只需要using terms from application "Mail"。您可以通过键入 command+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

【讨论】:

  • 如果它工作正常,我怎样才能正确测试它?我再次发送了电子邮件,但没有任何反应...
  • 在同一帐户上发送给您自己的电子邮件似乎不起作用...如果您从一个电子邮件帐户向另一个帐户发送电子邮件,即使在邮件中,它似乎也可以正常工作。或者你可以使用express222.com/email_test.php
  • 另外,检查它是否正常工作的一种快速方法是将display alert "something" 放在代码中的某处。
  • 确实如此,但我感觉这种自动触发不起作用。
  • 您是否已将脚本附加到规则中?
猜你喜欢
  • 2011-06-01
  • 1970-01-01
  • 2010-10-01
  • 1970-01-01
  • 2011-01-07
  • 2018-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多