mcomella.com
Posts   |   About

Gmail Per-label Notifications for FastMail

As someone who tries not to check their email often, I’ve relied on the Gmail Android app to notify me when urgent emails arrive. To do this, I:

  1. Use Gmail filters (through the web interface) to add a label to important messages: notify me
  2. Enable notifications in the Gmail app (Settings -> me@gmail.com -> Notifications)
  3. Disable any “Label notifications” enabled by default (e.g. Inbox; Settings -> me@gmail.com -> Manage labels -> Inbox -> Label notifications)
  4. Enable “label notifications” for notify me

Now I’ll receive notifications on my Android phone for urgent emails, labeled notify me, but not for other emails - great!

FastMail

I recently switched to FastMail, which does not support notifications on a per-folder basis (folders stand in for labels), so I needed a new solution. I found one in FastMail’s Sieve Notify extension.

FastMail uses the Sieve programming language to filter incoming emails. When a user uses the Rules GUI to create these filters, FastMail will generate the necessary Sieve scripts used behind the scenes. However, the GUI is limited so they allow users to write custom sieve code to filter mail in advanced ways.

Their Sieve implementation comes with many extensions, one of which is the Notify extension. Notify, when called from a Sieve script, can launch a notification from the FastMail mobile app with the user-specified custom text. Note that Notify can also be used to forward an email or send a message through twilio, Slack, or IFTTT.

Here are the basic steps to get Notify working:

  1. Write a custom Sieve script (through the web interface) to run Notify on desired emails (Settings -> Rules -> Edit custom sieve code; there will also be auto-generated Sieve code here)
  2. Disable notifications (yes disable!) in the FastMail app: this stops notifications for mail that isn’t using Notify (Device Settings -> Notifications)

Here’s an example Sieve script to open a notification for mail from a@b.com or x@y.xyz, keep the message, and stop futher filtering:

if 
  anyof(
  address :is "From" "a@b.com",
  address :is "From" "x@y.xyz"
  )
 {
  # Notify the app with the specified text
  notify :method "app" :options ["From","Full"] :message "$from$ / $subject$ / $text[500]$";
  
  # Keep the message and don't go through additional filters.
  # Without "keep", "stop" will discard the message so be careful!
  keep;
  stop;
}

See additional details at the Notify documentation here. I paste this script in the bottom-most custom sieve section (below the rules generated from the Organize Rules GUI) though it could be moved anywhere. Once the script is added and notifications are disabled, the FastMail app will send notifications if and only if they match the Notify filters!

This solution comes with some pros:

And cons (on Android, at least):

An alternative solution

Before finding this solution, I first came up with another: I installed a local mail client that could enable/disable notifications at the folder level (K-9 Mail) and mimicked the Gmail app solution. This was unsatisfactory to me because it required me to check two folders for my new mail - Inbox and notify me - since a FastMail message can only exist in one folder, unlike Gmail labels. This solution also forced me to configure an unfamiliar client (K-9 isn’t simple…) and to trust it with login credentials.


This post is written by Michael Comella, a software developer with Android and performance experience.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Creative Commons License