Although I use Thunderbird for work emails, due to its ability to manage HTML and accept meeting invitations, my personal email client of choice is NeoMutt. I wanted to be notified of new emails automatically, using the same system that Thunderbird and other applications use. Fortunately NeoMutt has the new_mail_command option, which will run an arbitrary command when a new mail is received, with placeholders for the number of new and unread messages.
On Linux, there is a generic notify-send command which will send a message using the Desktop Notification Specification, which means it will work with most desktop environments (Xfce in my case). This command has a few options, but at its most basic it will accept a simple string, e.g.
notify-send ‘new email received’
You can run the above command in a terminal and you should see a notification immediately – in my case it’s at the top right of the screen.
We can set this in our NeoMutt config with:
set new_mail_command=”notify-send ‘new email received'”
We can provide a bit more information with the %n and %u placeholders, which show the number of new and unread messages respectively:
set new_mail_command=”notify-send ‘new email received’ ‘%n new messages, %u unread.'”
Finally, we add an ampersand to the end of the command, so that it runs in the background and doesn’t halt NeoMutt:
set new_mail_command=”notify-send ‘new email received’ ‘%n new messages, %u unread.’ &”