Mac Brain: Automatically Processing Email with Mail.app

Similar to the way that Hazel can automate moving around files, Mail.app can process emails in your inbox based on rules you set. Rules are often used used to flag messages and move them to folders based on certain conditions, but that’s not very exciting.

Processing email is a problem. There’s a lot that comes into your inbox and you continually have less attention to pay to it. I get a lot of recurring notification-type messages for things I need to do, like an email from my bank letting me it’s time to pay my monthly credit card bill. A thing that repeats with the same input and output is a thing that should be automated.

Routing Emails

Part of automation is setting something and never having to see or think about it. To make that part happen, I had to route all of the emails I wanted automatically processed in a separate email account1 so I never saw them in my main inbox. I set up a second Fastmail (referral link) account that would be used only on the mini server. Anything I routed to that email address would be processed. In Fastmail, I can also easily set up aliases so different to: addresses would trigger different things. I could set up omnifocus@myserveraddress.com to process OmniFocus tasks or have emails that go to alerts@myserveraddress.com ping my phone2 when important messages come in.

Once I had this new address set up, I had to configure the services (my bank for example) to send these notifications to that correct address. About half of my banking services allowed me to set up these notifications to go to a secondary address and the ones that didn’t had a unique from or subject that I was able to use server-side filtering to redirect any of those emails coming into my personal account to my Brain account.

This got me to a place where all of the emails I wanted to automatically process were in an inbox on my mini.

Setting up the Rules

Again like Hazel, setting up Mail.app rules is pretty easy once you know what to look for. For emails from my bank, I looked at the history of their messages and checked for a unique address for bill notifications or a consistent convention for the subjects of the emails. I wanted to be precise. Doing wildcards to redirect and forward all emails from @bank.com or whatever could mean that important emails I did need to see would get batched into an inbox I didn’t look at often.

All of these emails had unique conditions which could be passed on to a specified action, like the from: containing billnotifications@mybank.com or the subject is equal to Your bill has arrived.

We’ve captured the messages, now the fun part: doing cool stuff with boring emails.

Turning Emails to Actions

Once we’ve gotten to this point, we know the specific intention of the email. It has passed all of the tests and we just need to do something with it.

Most of the emails that come into my work or personal inbox I process and capture into OmniFocus. I wanted to be able to automate this step for the emails I could. David Sparks put together this great Applescript to run within Hazel to add actions to OmniFocus when he scans documents that match specified criteria. Sound familiar? We’re basically doing the same thing but the input is an email not a OCR’ed document and the rules are processed by Mail.app and not Hazel.

I have Mail.app “perform the following actions” when it receives a matching email:

  • Move it to Archive
  • Mark it as read
  • And run an Applescript on it

My Applescript is exactly the same as David’s but I’ve added in the time it was created as the Start Date of the OmniFocus action. To do this, you just need to add start date:theDate to the list of task properties. This helps me recognize new automatically added actions in one of my OmniFocus perspectives.

Now—all automatically—when my bank sends out an email to let me know my statement is ready, it filters into my Brain email account, gets checked through Rules, and when it matches, it adds an OmniFocus task to “Review and Archive my bank statement” or create two separate tasks like “Review credit card statement” and “Pay off credit card balance”.

This rule is set up to run a “Create OmniFocus Task” Applescript, but you can set it up to trigger any Applescript you can think of.

The Point of Automating

Sure, it’s cool that a computer can check your email for you but the value comes from reducing the amount of time and attention you need to be spending processing repetitive items and reducing the friction of getting something into your outboard brain. Not only is the action being put into your outboard brain, but an outboard brain is doing the processing now too. In a lot of cases it works to set repeating tasks for something like bills but I find it more direct to have the inputs of the notifications and the action align rather than scheduling a task and have it start a couple days earlier than the bill is available because of a long weekend or something. It’s all small things, but the reduction of the attention required to process along with being able to rely more on your outboard brain because of its ability to capture and process things without your input is what makes the automation worth the setup investment over time.

  1. I played around with server-side archiving, but Mail seems to only run rules on things that are in your inbox.↩︎

  2. I’ll walk you through this soon. Having a server set up to send you an SMS is pretty cool.↩︎