Skip to content
This repository has been archived by the owner. It is now read-only.
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Goal: Get continuously all emails from an IMAP server into GMail without loosing emails, and using all features (filtering, spam detection) of GMail.

Imap2Gmail uses imap IDLE to poll emails from an IMAP server and imports them into a GMail account via GMail API Users.messages.import, this ensures that mail scanners and filters are applied in GMail. If successful, the email is moved to the folder imapfoldermoved on the IMAP server. imap2gmail is supposed to run on some server 24/7 which can send emails for error notification. Disable SPAM mail filtering on the IMAP server.

I wrote this little program because (i) normal GMail doesn't poll IMAP servers and (ii) "redirecting" emails to GMail is very unreliable, in particular with Exchange servers.

How to use

  • Generate your own GMail API keys for imap2gmail, see below.
  • Download and extract the zip or wget It is so large because it contains a Java runtime environment.
  • Run imap2gmail-linux/bin/imap2gmail or while : ; do imap2gmail-linux/bin/imap2gmail ; sleep 60 ; done (for low-end systems, where the jvm can be killed due to out-of-memory).
  • After the first start, the settings file ~/imap2gmail-settings.txt will be created, which you have to edit. See below.
  • On the second start, you have to give imap2gmail access to your gmail account, follow the instructions (note: in browser, click advanced, then proceed...).
  • I run imap2gmail in a GNU screen that is started automatically.

GMail API keys

Unfortunately, you need to get your own GMail API keys for imap2gmail; there is a quota for API usage and I don't want to deal with this.

Follow , which means:

  1. Go to click
  2. Select Create a project, Continue, then on the Add credentials to your project page, click the Cancel button.
  3. Select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
  4. Select the Credentials tab, click Create credentials and select OAuth client ID.
  5. Select the application type Other, enter the name imap2gmail, and click the Create button.
  6. Copy and paste the client id and secret id into the imap2gmail.txt settings.

Example settings file

# the server from which emails are pulled
# warning email settings
# your GMail API keys for imap2gmail
# maximum email size, larger emails will be quarantined.

How to develop, compile & package

  • Get Java 13 from
  • check out the code (git clone ... or download a zip)
  • I use the free community version of IntelliJ IDEA, just open the project to get started.
  • Run: ./gradlew run
  • Package:
    • Download a suitable JDK for the target platform (if not same as development) from
    • Point to it JDK_LINUX_HOME=/.../openjdk-13_linux-x64/
    • ./gradlew clean dist. The resulting (~40 MB) ZIP file is build/image-zip/

Used frameworks


No description, website, or topics provided.



No packages published