Easily refresh all your POP3 E-Mail accounts linked to Gmail with a bookmarklet

blog post cover image Easily refresh all your POP3 E-Mail accounts linked to Gmail with a bookmarklet

Published December 8, 2021Last updated March 26, 2024

Are you receiving your emails of your linked email account in Gmail late? This blog post introduces a simple, yet effective solution - a bookmarklet. With just a single click, you can fetch emails from all your linked accounts.

A missing feature in Gmail is that you cannot refresh your linked email accounts conveniently. It seems to bother the community as you can see here and here in the Gmail Help Community, and here at stack exchange. You can speculate that Google doesn't like that feature, maybe thinking people will use their Gmail account or switch to G-Suit aka Google Workplace. Anyways, this shouldn't be the topic here.

The current state with Gmail

The way Google is calculating the interval to check on your mail accounts is depending on how often you receive an email. This technique is especially not helpful when you are waiting for e.g. a signup confirmation email. Some resources stating a click on the refresh icon will trigger your accounts to get refreshed. A quick check on the settings page shows that it's more like a dummy and doesn't refresh POP3 mail accounts.

Gmail dummy refresh button
Gmail dummy refresh button

An effective way of retrieving your emails is through “Settings” → “Accounts and Import” → “Check email from other accounts”-section and clicking on “Check mail now”. However, this is a tedious and annoying process that screams for automatization.

Screenshot of Gmail settings to manually refresh email accounts
Manually refresh email accounts

Bookmarklet to check all mail accounts in one click

Let's solve this with a simple bookmarklet! A bookmarklet is JavaScript code saved as a bookmark, which can be run with a single click.

Here is the code, I'm going to explain it later.

Copy
javascript:
(function () {
    const gmailWindow = window;
    if(gmailWindow.location.href.indexOf("https://mail.google.com/") === -1){
        alert('You have to run the bookmarklet from a Gmail window');
        return;
    }
    gmailWindow.location.assign('https://mail.google.com/mail/u/0/#settings/accounts');
    const xpath = "//span[text()='Check mail now']";
 
    const refreshAccounts = () => {
        const selectedNodeElements = gmailWindow.document.evaluate(xpath, gmailWindow.document, null, XPathResult.ANY_TYPE, null);
        let currentNode = selectedNodeElements.iterateNext();
        if (currentNode === null) {
            setTimeout(refreshAccounts, 100);
        } else {
            while (currentNode) {
                currentNode.click();
                currentNode = selectedNodeElements.iterateNext();
            };
            gmailWindow.location.assign('https://mail.google.com/mail/u/0/#inbox');
        };
    };
    setTimeout(refreshAccounts, 100);
})();

View Gist on GitHub

What the email bookmarklet does

  1. Due to security reasons (CORS) you have to run the bookmarklet from your Gmail tab. Therefore, the bookmarklet will first check if you're in the right window. In my case I always have the Gmail window pinned to my tab bar.
  2. It will then automatically navigate to your Gmail Settings.
  3. After 100 milliseconds it will check if the Gmail Settings have loaded completely. To do so, it will try to access the links to refresh each POP-account. This is being done through XPath since IDs and classes will change over time.
  4. If it can succesfully access the links, the links will get clicked and it will load the Gmail inbox again. If the page is not ready yet, it will try again after 100 milliseconds.
  5. Done, now your inbox with all your email accounts should be up-to-date! (thanks to Nathan Stretch at this point for speeding up the execution time of the script)

⚠️ Attention, there is a pitfall

You cannot simply copy the JavaScript code, it needs to have some adjustment: No line breaks or single-line comments are allowed and you have to put a 'javascript: ' at the beginning. Here you'll find a way to quickly get rid of your line breaks.

The final bookmarklet for Gmail

Here is the code of the bookmarklet without line breaks:

Copy
javascript: (function () { const gmailWindow = window; if(gmailWindow.location.href.indexOf("https://mail.google.com/") === -1){ alert('You have to run the bookmarklet from a Gmail window'); return; } gmailWindow.location.assign('https://mail.google.com/mail/u/0/#settings/accounts'); const xpath = "//span[text()='Check mail now']"; const refreshAccounts = () => { const selectedNodeElements = gmailWindow.document.evaluate(xpath, gmailWindow.document, null, XPathResult.ANY_TYPE, null); let currentNode = selectedNodeElements.iterateNext(); if (currentNode === null) { setTimeout(refreshAccounts, 100); } else { while (currentNode) { currentNode.click(); currentNode = selectedNodeElements.iterateNext(); }; gmailWindow.location.assign('https://mail.google.com/mail/u/0/#inbox'); }; }; setTimeout(refreshAccounts, 100); })();

The only thing you have to do is to insert the JavaScript code as URL of a bookmark to add the bookmarklet to your browser.

Screenshot of adding bookmarklet to browser
Create bookmarklet in browser

Note: Gmail takes a few seconds to refresh the inbox so you have to wait a bit after clicking the bookmarklet and refresh the inbox page (CMD/STRG + R)

Using Gmail in a different language than english

If you are using Gmail in a different language, you have to adjust the “Check mail now” at the following position, so the script will be able to access the refresh links:

Copy
const xpath = "//span[text()='Check mail now']";

Enjoy!