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
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.
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.
Note: The directory we created with the above command will store your email.
Change directory with the following command.
Now create the getmail.gmail file with the following command.
Paste the following text.
[retriever] type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = firstname.lastname@example.org
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
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
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/getmail.gmail