How To Backup Gmail With getmail Tool

All my life 'depends' on my gmail account. I email my friends, contact people i want to know or work with, send documents and stay updated with the latest blogs. Now, imagine what will happen if i forget my username or password and lose my gmail account. All my contacts, information and documents will be gone!

What to do? I know a nice command line tool that can help me and you. It is called getmail, a tool that can retrieve messages from POP3, IMAP4, and SDPS mailboxes.

Use the following command to search for getmail tool.

sudo apt-get cache search getmail

How To Backup Your Gmail With getmail Tool

Install the getmail tool.

sudo apt-get install getmail4

After the getmail tool is installed we need to create a directory for storing the mbox file. Run the following command to create the .getmail directory in your home directory.

mkdir ~/.getmail

Where are we going to store our emails? We need to create another directory, run the following command to create the gmail-archive directory inside the home directory. Make sure you are in the home directory.

mkdir ~/gmail-archive

Note: The directory we created with the above command will store your email.

Change directory with the following command.

cd ~/.getmail

how to backup gmail in ubuntu

Now create the file with the following command.


Paste the following text.

[retriever] type = SimplePOP3SSLRetriever
server =
username = [email protected]
password = bobpassword

[destination] type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox

[options] # print messages about each action (verbose = 2)
# Other options:
# 0 prints only warnings and errors
# 1 prints messages about retrieving and deleting messages only
verbose = 2
message_log = ~/.getmail/gmail.log

how to backup gmail in ubuntu

Go under destination and edit the file like shown below.

[destination] type = Maildir
path = ~/gmail-archive/

Run the following command to make the three directories used by the Maildir format.

mkdir ~/gmail-archive/tmp ~/gmail-archive/new ~/gmail-archive/cur

how to backup gmail in linux

Open the config file again and under retriever add your username and your password. Then run the following command to backup your gmail.

getmail -r ~/.getmail/

how to backup gmail in linux

Oltjano Terpollari 3:00 am

About Oltjano Terpollari

Oltjano Terpollari is a very passionate computer geek studying python, linux, netcat power tools and living a binary life. He goes by the nickname Ambition and is very happy living a science life. He also loves technical blogging and sharing his knowledge with others.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.