Mailnag

Automatic Webmail Notifications in Linux

I use webmail for all of my email accounts as I find it much more convenient than setting up a local mail client like Thunderbird. For what seems like forever, I had been using a Firefox Add-On called X-notifier to alert me when I receive new mail. It was a cool little utility that allowed Firefox to regularly notify me of new mail from my various email accounts. User submitted scripts provide compatibility with just about every mail provider out there.

A couple of years ago, Mozilla announced they would be completely redesigning Firefox as well as its Add-On development platform to provide a more secure browser. This meant that Add-Ons which allowed for customization via user scripts would no longer work. In preparation for this change, X-notifier released a new version that stripped this ability and limited its functionality to only a couple major mail providers. I was still able to reinstall an older version of X-notifier and go on my merry way, but I knew it was only a matter of time before I would need to find a new solution altogether.

Well as some of you may have noticed, Mozilla has already released versions of Firefox which no longer support older Add-Ons. This left me scrambling for a new email solution. My prayers were answered in the form of a utility called Mailnag.

There are already a few updated Firefox plugins like the aformentioned X-notifier, which allow you to check major mail providers like Gmail & Yahoo with the latest versions of Firefox. The reason why I prefer Mailnag is that it can be configured to check any IMAP or POP provider and takes the reliance on Firefox completely out of the equation. Mailnag is a standalone service that runs in the background upon login and integrates into the default mail icon in your Linux system tray.

Synopsis

Installing the Mailnag

As most Linux users know, installing packages vary greatly from distro to distro so this section will be limited to installing Mailnag on Ubuntu 17.04. The rest of the guide will be applicable to most distros.

While Mailnag itself is already in the default Ubuntu repositories, the additional Mailnag plugin we want is only in the 3rd party Mailnag repo. We'll add that in first and then install Mailnag and the plugin together.

Open a terminal and run the following to add the Mailnag repository and complete the installation.

sudo add-apt-repository ppa:pulb/mailnag
sudo apt update
sudo apt install mailnag mailnag-messagingmenu-plugin

Appease the Mailnag

Now that everything is installed, launch Mailnag via the Unity Launcher, click on the Accounts tab and hit the + button.

Add Mail Accounts
Add Mail Accounts

Setting up your Gmail account is as easy as selecting Gmail as your Account Type and entering your email address and password. As a bonus, you can even have Mailnag check folders other than your Inbox by clicking on the optional Folders dropdown. This is useful for users who automatically sort their incoming mail into separate folders. There's nothing wrong with being that meticulous. We should all strive to be that organized...and anal retentive...*cough*.

Gmail Setup
Gmail Setup
*Bonus Tip:If you use Two-Factor authentication with your Gmail account, which you should by the way, Mailnag won't work out of the box. There is a workaround for this however. Gmail allows you to create a randomized App Password that bypasses Two-Factor authentication and can be used in lieu of your Gmail password with Mailnag or any other mail checker or client. I realize this does defeat the purpose of Two-Factor authentication, but it's the only option you have if your application or client doesn't play nice with it. For more info on this setup check out this Gmail Help Page

If you want to setup a different mail provider, go to your provider's website or contact them for their IMAP or POP server settings. Select Other (IMAP) or Other (POP3) as your Account Type and enter the settings you just looked up. If you're IMAP provider supports it, make sure Enable Push-IMAP is checked unless you're checking multiple folders.

IMAP Setup
IMAP Setup

POP Setup
POP Setup

The last Mailnag setting we want to change is in the Plugins Tab. Enable the MessagingMenu by clicking the checkbox next to its name. This will allow Mailnag to integrate into the default Unity Mail icon in the system tray.

Mailnag Plugin
Mailnag Plugin
*Bonus Tip: If you use another Desktop Environment like GNOME, which all Ubuntu users will be using come 17.10, you can install the Mailnag GNOME-Shell plugin instead. It's called gnome-shell-mailnag and can be installed from the same Mailnag repository we added earlier.

By default, Mailnag will immediately notify you of new messages as soon as they are received on all IMAP accounts. This isn't the case if you setup your IMAP account to check multiple folders or if you use a POP3 account. In these scenarios, Mailnag will check for mail every 10 minutes.

*Bonus Tip: All Mailnag settings are located in ~/.config/mailnag/mailnag.cfg. To change how often Mailnag checks POP3 accounts and IMAP accounts that check multiple folders, change the poll interval setting which by default is set to 10 minutes. Be careful not to set this setting too low as some POP servers may block you for repeately hammering their servers.

Webmail Shortcuts Cuz Convenience

If techs are known for anything, its making their lives as easy as possible. This last section is optional as we already have our webmail notification setup, but it would be a huge PITA (the acronym and not the bread which I love) if everytime we got a mail notification, we were forced to manually launch our browser and then surf to our webmail site. I'm much too lazy for that.

You may have discovered that if you click on the Open Mail Reader link under Mailnag, it launches the default mail client, most likely Thunderbird. Well that kinda defeats the whole purpose of using webmail. To combat this behavior, we'll need to install another utility called Desktop-Webmail to ease our suffering #FirstWorldProblems.

Launch a terminal and install Desktop-Webmail by doing the following.

sudo apt install desktop-webmail

Launch Desktop-Webmail and you'll be prompted to choose a Webmail provider. If you use Gmail, Hotmail, Yahoo or Zoho then this will be real easy. If not, just select Gmail and bear with me. Also, make sure to uncheck Ask again so you won't be prompted to configure Desktop-Webmail again.

Configure Desktop-Webmail
Configure Desktop-Webmail

Now we'll make Desktop-Webmail the default mail application for Ubuntu. Open the Unity Launcher search for Details and click the icon.

Select Default Applications from the menu and click the Mail dropdown which should currently be populated with Thunderbird. Select Desktop-Webmail instead and close the window.

Set Default Mail App
Set Default Mail App

Now when you click on Mailnag's Open Mail Reader link under the system tray mail icon, your default browser will automatically launch, if it's not already open, and take you directly to your webmail site. Convenience is my BFF.

Shortcuts for the "Alternative" Mail Provider

To the readers who don't use one of the 5 webmail providers listed above, I haven't forgotten about you. You'll need to do one additional step which is manually edit the desktop-webmail.ini file and enter your Mail provider's webmail URL.

nano ~/.config/desktop-webmail/desktop-webmail.ini

## Original desktop-webmail.ini
[Config]
remember=true
default-provider=Gmail
default-url=https://mail.google.com/mail/?extsrc=mailto&url=%s
default-inbox=https://mail.google.com/mail

## Updated desktop-webmail.ini
[Config]
remember=true
default-provider=FakeMail  ##<-- Change to your Mail Provider Name
default-url=https://mail.fakemail.com/webmail  ##<-- Change to your Webmail URL
default-inbox=https://mail.fakemail.com/webmail ##<-- Change to your Webmail's Inbox URL if different from "default-url"

Mailnag is now setup to launch your mail provider's webmail site instead of Gmail.

How Do I Open Multiple Sites Genius?

If you have Mailnag setup with multiple mail accounts, you may be wondering how Desktop-Webmail can be setup to launch each one. Well the short answer is it can't, but as usual I have a workaround for that. This is a solution I'm not proud of and am currently looking for a better method if anyone has one.

If you're lucky enough to have a provider like Gmail or Zoho that allows the checking of 3rd party POP accounts, you're going to have to choose one of them to be your "main" account. This account will be used to check all other email accounts which introduces an inherent security risk as now one account has access to all others. I would definitely think twice about attempting this if you intend to check both work and personal emails. There's also potential space issues as all new mail from your POP accounts will get downloaded to your main account.

With all that being said, if you'd still like to set this up, you'll need to make sure all email accounts other than the main account has POP3 enabled. You'll then need to setup your main account to check for mail on your other accounts. Make sure you have each mail providers' POP3 settings beforehand. If you're attempting this with Gmail, here's a Gmail Support Page that walks you through it.

Since all of your emails will now show up in different folders within your main account, you can even pare down your Mailnag config to just your main account and enable it to check each mail folder along with your main Inbox. If you find it too hard to keep track of which email belongs to which account, you can keep Mailnag setup as is with separate accounts. Keep in mind that depending on how often you have your main account checking the other accounts for new mail, you may get notified by Mailnag of new messages before the main account has had time to download them.

So that about wraps it up. This method is by no means perfect, but it does work. If anyone out there has a better alternative or has additional tips to add, feel free to comment below.

Please Share Me, I'm Lonely

One Response to Automatic Webmail Notifications in Linux

  1. Hi,
    I love your article about Mailnag.
    I don’t like Firefox, Thunder-mail, deleted both from my Linux OS and using Opera and Mailnag instead.
    Didn’t like Mailnag’s sound notification (it was giving me a hart attack every time) so I have changed it to a nice short .ogg sound, it works great.
    Never heard of Desktop-Webmail shortcut before, I installed it now, it’s very nice to have, thank you!
    But I do have one problem with Mailnag: After suspend or logout it stops checking for new emails. I’ve been googling about this for weeks to find a fix but no luck. I found posts on Linux forums people complaining about the same problem but no fix. Just wondering if you might have one. Right now after coming back from suspend I have to open Mailnag and turn it off and on again so it keeps working. I’m sure a lot of guys would be very happy to find a solution for this!
    Your article was very helpful, thank you very much!