Need to back up email? Consider skipping the complicated GUI backup tools, and going with IMAP Grab instead.
Check Python Version
IMAP Grab is a Python script available on Github that allows users to directly “grab” IMAP mail to archive it later. To use this script, you’ll need to install Python 2.3.3 or later. To see if you have the correct version of Python on your Linux PC, open up a terminal and run a version check.
As long as it returns Python 2.3.3 or higher, you’re good to go. If you don’t have the required version of Python, consider updating your Linux PC’s packages.
Download IMAP Grab
When Python is taken care of, use the Git tool to clone the latest version of the IMAP Grab tool.
Note: this part of the tutorial requires the Git package. To install it, search for “git” and install it.
git cloneÂ https://github.com/ralbear/IMAPbackup.git
Using theÂ CDÂ command, move the terminal into the new “IMAPbackup” directory.
‘); if (navigator.appVersion.indexOf(“Mac”)!=-1) document.write(”);
The script is on your PC, but it’s not going to work without the “Getmail” dependency.
sudo apt install getmail
sudo apt-get install getmail
sudo pacmanÂ -S getmail
sudo dnf install getmail
sudo zypper install getmail
Using IMAP Grab
Before we can back up email, we’ll need to use IMAP Grab to list all available mailboxes inside of the email account. To do this, fill out this command. There are several aspects to this command. In the example, we’ve written out “test” URLs, users and passwords. Change the command following these steps.
First, change the server afterÂ -sÂ toÂ theÂ IMAP server your email account uses. NotÂ sureÂ whatÂ theÂ serverÂ address is? Guess by taking theÂ root domain, and addÂ “imap” in front of it. For example, Mail.com has anÂ IMAP address of imap.mail.com. If that doesn’t work, you can always Google this information.
Next, change the test user afterÂ -uÂ toÂ your email address, andÂ addÂ your email account’s password afterÂ -p.
python imapgrab.py imapgrab.py -l -s imap.test.com -u firstname.lastname@example.org -pÂ emailpassword
Run this command in the terminal, and the script will print out all available mailboxes.
Back Up Email
IMAP Grab can download email from any Mailbox folder. To download, first, create a directory where your email will download.
Then, use IMAP Grab to download everything. Like before, be sure to changeÂ -s,Â -u, andÂ -pÂ with the correct information.
python imapgrab.py -d -v -M -f ~/email-backups -s imap.test.com -u email@example.com -p emailpassword -m "_ALL_"
Keeping “_ALL_” after theÂ -mÂ option in the command will tell the script to download absolutely everything in your email account. Most users should use “_ALL_”, especially if you don’tÂ understand the script’s syntax. Another good reason to stick with this option isÂ if you’ve got a lot of folders, and you don’t want to spend hours specifying everything in the command.
Note: To download only a specific folder from an email account with IMAP Grab, change “_ALL_” with some of the inbox folder names that the script lists in the previous section.
Encrypt Email Backup
Downloading your email to back it up is a great idea, especially if you want to always have a record of it offline. Unfortunately, these downloads are not private, and anyone can easily read your personal messages if they get access to your PC. If you’d like to create an encrypted archive of your email backup, follow these steps. First, useÂ tarÂ to create an archive of the email backup folder.
tar -jcvf email-backup.tar.bz2 email-backups
Depending on the size of yourÂ ~/email-backupsÂ folder, compression may take a bit of time. Let the compression tool run, and soon after you’ll have a new archive with all your messages in it. From here, use the GnuPG tool to start the encryption.
gpg -cÂ email-backup.tar.bz2
Running gpg -cÂ will prompt the user to set a password for the new encryption archive. Use a secure password that is memorable.Â Encryption, like creating the archive, takes time to complete and the larger your backup is, the longer it will take to encrypt it. When the GPG encryption process finishes, you’ll notice anÂ email-backup.tar.bz2.gpg file. This is the locked archive. Nobody will be able to access this file without the passcode you entered. It’s completely secure, so feel free to takeÂ email-backup.tar.bz2.gpgÂ and upload it to Dropbox, Google Drive, home servers and etc.
Now that the backup archive is locked with GPG, we have no need for the unencrypted archive. Using theÂ rmÂ tool, delete it.
So, you’ve used GPG to lock up and secure your email backup. How do you decrypt it? Simple! Open up a terminal, and use the GPG decrypt command to unlock the archive.
When the decryption command runs, you’ll need to enter the password you set. Once you do,Â email-backup.tar.bz2 will appear. At this point, you’ll be able to use theÂ tarÂ command to extract the emails from the archive.
tar -xvfÂ email-backup.tar.bz2