Automator / AppleScript to process incoming emails in Mac Mail

亡梦爱人 提交于 2019-12-01 07:09:14

问题


I'm designing an app that allows users to email me crash reports if my app ever crashes. I'd like to leave Mac Mail running on a computer and when an email comes through, an automator script / AppleScript runs to process the contents of the body of the email.

I've got the entire parsing/processing done in a python script, except I have to manually copy the contents of the email into a file and then run my parser on that file.

What's the best way to set this up so I can the contents of the email be pushed into my parsing script?

Many thanks!


回答1:


Probably the simplest approach is to define a Mail.app Rule. You can set up filtering conditions to specify the set of incoming email to apply the rule to and among the rule actions you can specify is one to run an AppleScript on incoming messages. Rules are managed with Mail.app Preferences -> Rules. Apple supplies examples of Rule Action scripts with Mac OS X. Look in /Library/Scripts/Mail Scripts/Rule Actions or search the web.




回答2:


Here's a script that extracts from email into a file using a mail rule: MacScripter / Mail rule script for message export. Might be good for sample code for what you're doing.




回答3:


Use the Dictionary in Applescript Editor to see the properties of mail and you'll quickly be able to see the properties of any mail message. Here's a quick and dirty example of getting the content of a mail message.

tell application "Mail"
    set the_messages to selection
    repeat with this_message in the_messages
        set mytext to content of this_message
    end repeat
end tell

Modify the script linked to above that copies output to a temporary file and then pass that file to your Python script to act on.



来源:https://stackoverflow.com/questions/4565784/automator-applescript-to-process-incoming-emails-in-mac-mail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!