Install Getmail :
Download Getmail, open terminal and type
tar xzvf getmail*.tar.gz
cd [unpacked directory]
sudo python setup.py install
Configure Getmail :
Create a file at ~/.getmail/getmailrc and put the following text in it
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = example@gmail.com
password = password
[destination]
type = Mboxrd
path = ~/gmail-backup/gmail.mbox
[options]
verbose = 2
message_log = ~/.getmail/gmail.log
Create the mbox file ~/gmail-backup/gmail.mbox
Run getmail :
getmail