How to Bulk Move All Email From One Account to Another Using the CLI

  • Home /
  • Blog Posts /
  • How to Bulk Move All Email from One Account to Another using the CLI

If you find yourself in a position where you need to sync all emails from one account to another, then you can use the imapsync command-line tool to bulk copy, or move everything for you.

Step 1 – Get imapsync

You need to get the imapsync tool running locally.

It can be found here https://github.com/imapsync/imapsync

Alternatively, if you are using a Mac and have homebrew installed, then you’re in luck!

Simply brew install imapsync and you’re ready.

Step 2 – Enable imap on the accounts

By default, imap is often disabled on the email server. We will explore Gmail in this case to test a sync.

In Gmail, under Settings, find Forwarding and POP/IMAP and make sure that imap is enabled.

Also make sure that Auto-Expunge is off, and select Immediately delete the message forever. Make sure that Folder size limits are not set.

(Gmail imap settings)

Step 3 – Configure your account creds

You will need the username and password for each account, so have them to hand!

Step 4 – Run the command!

You can now run the tool to transfer all emails from account1 to account2.

Sync from host1 to host2 and delete after success on host1

This option will allow you to automatically sync everything in source_account (host1) to destination_acount (host2) and on successful migration of email, it will delete the email/s in the source_account.

This option is great if you are migrating from 1 account to another:

imapsync \
    --host1 imap.gmail.com --user1 [email protected] --password1 MyP@$$w0rd! \
    --delete1 \
    --host2 imap.gmail.com --user2 [email protected] --password2 MyP@$$w0rd!

Sync from host1 to host2 without deleting anything

If you don’t want to delete any email/s in your source_account (host1) after successful email transfers, then you can simply leave out the --delete1 flag, as follows:

imapsync \
    --host1 imap.gmail.com --user1 [email protected] --password1 MyP@$$w0rd! \
    --delete1 \
    --host2 imap.gmail.com --user2 [email protected] --password2 MyP@$$w0rd!