A logo showing the text blog.marcnuri.com
Español
Home»Java»Incremental E-Mail backup and migration using mnIMAPSync

Recent Posts

  • Fabric8 Kubernetes Client 7.2 is now available!
  • Connecting to an MCP Server from JavaScript using AI SDK
  • Connecting to an MCP Server from JavaScript using LangChain.js
  • The Future of Developer Tools: Adapting to Machine-Based Developers
  • Connecting to a Model Context Protocol (MCP) Server from Java using LangChain4j

Categories

  • Artificial Intelligence
  • Front-end
  • Go
  • Industry and business
  • Java
  • JavaScript
  • Legacy
  • Operations
  • Personal
  • Pet projects
  • Tools

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • September 2019
  • July 2019
  • March 2019
  • November 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • December 2017
  • July 2017
  • January 2017
  • December 2015
  • November 2015
  • December 2014
  • March 2014
  • February 2011
  • November 2008
  • June 2008
  • May 2008
  • April 2008
  • January 2008
  • November 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

Incremental E-Mail backup and migration using mnIMAPSync

2015-11-25 in Java / Tools tagged Backup / E-Mail / Mail / Migration / Open Source / Tutorial by Marc Nuri | Last updated: 2021-02-21
Versión en Español

Yet another IMAP syncing tool

Two years ago when I first released mnIMAPSync, there were several mail syncing tools available. The problem with most of them was that when performing incremental E-Mail backups or migrations, some of the e-mails, mostly the ones that didn't conform the RFC (3501), were being duplicated in the mirror server. This was due to invalid headers and an invalid or non-existent message-id.

With no tool available in hand, I had to code one myself that did the job correctly. The main difference between mnIMAPSync and the other available tools is that mnIMAPSync checks several headers for each message and creates a rapid access index so that when the mirror server gets crawled, existing messages won't get duplicated.

Requirements

Java

This tool is coded in java, so you will need a valid JRE. If you don't have Java installed on your system, visit www.java.com/download and download the newest release.

A Screenshot of the Java Download Page
A Screenshot of the Java Download Page

Follow the site instructions to download and install the Jave Runtime Environment.

mnIMAPSync

Next you have to download mnIMAPSync. You can either download the latest release, or the latest source code from Github and compile your jar. To download a precompiled release visit https://github.com/manusa/mnIMAPSync#releases and download the latest.

A Screenshot of the Java mnIMAPSync Page
A Screenshot of the Java mnIMAPSync Page

Once you've downloaded the Zip distribution, extract the package contents to a directory using your favorite compression tool.

Running the program

This is a command-line application, so you will need a terminal/cmd window.

In windows you can use cmd.exe (Start->Run->cmd.exe)

To use the program you simply have to specify the required command line arguments. You can find a list of these arguments in the program homepage.

For this tutorial, we are going to migrate a GMail account to a regular mail account in a personal server. If you execute the process on a regular basis, each migration will run incrementally and the process will only copy messages and folders that don't exist in the target server.

1java -jar mnIMAPSync.jar                                         \
2  --host1 imap.gmail.com --port1 993                             \
3  --user1 myuser@gmail.com --password1 mypassword --ssl1         \
4  --host2 my.server.com --port2 143                              \
5  --user2 backupuser@my.server.com --password2 backuppassword    \
6  --threads 3 --delete

The above command will sync a source account in gmail to a backup account inmy.server.com.

host1, port1, user1, password1 and ssl1 are the parameters that specify the source server connection and authorization options. In this case we will connect to gmail's imap server using ssl.

host2, port2, user2 and password2 are the parameters that specify the target server connection and authorization options. In this case we are connecting to my.server.com using a regular connection (not ssl encrypted).

threads parameter indicates the number of threads to use. In this case, there will be 3 thread workers, so the program will make 3 connections to the source and target server to run the tasks in parallel.

delete is an optional parameter that indicates if we want to delete folders and messages in the target server that no longer exist in the source server.

A Screenshot of a completed execution of an mnIMAPSync process
A Screenshot of a completed execution of an mnIMAPSync process
Twitter iconFacebook iconLinkedIn iconPinterest iconEmail icon

Comments in "Incremental E-Mail backup and migration using mnIMAPSync"

  • Avatar for Eduard
    Eduard
    2019-09-10 04:12
    Releases not avaliable...
    https://www.marcnuri.com/file/mnIMAPSync-release-0.0.3-alpha.zip
    404 File not found
    • Avatar for Marc Nuri
      Marc Nuri
      2019-10-05 06:51
      Sorry, this post is really outdated and also the Readme page in GitHub.

      Download latest release from https://github.com/manusa/mnIMAPSync/releases

      https://github.com/manusa/mnIMAPSync/releases/download/v0.0.4/mnimapsync-all.jar

      I'll try to update this post/Readme soon to show alternative ways of running (Docker)

Post navigation
Spring Data JPA + EclipseLink: Configuring Spring-Boot to use EclipseLink as the JPA providerRunning Apache Tomcat and Apache HTTPD on port 80 simultaneously
© 2007 - 2025 Marc Nuri