I'm just following this post: https://wiki.archlinux.org/index.php/Backup_Gmail_with_getmail
This post is duplicating most of what's done there (I like the Arch tutes -- well written and thorough) so this is more of a 'yes, I followed it and it works' kind of posts.
Don't forget that gmail has an imap bandwidth limit of ca 2.5 GB per day: https://support.google.com/a/bin/answer.py?hl=en&answer=1071518
First install getmail4. You can probably ignore bug =#633799 (I'm assuming that you use apt-listbugs and receive the warning below -- if not, you probably shouldn't be using testing...)
sudo apt-get install getmail4#633799 - getmail causes irrecoverable mail corruption when using mboxmkdir ~/.getmail touch ~/.getmail/getmailrc chmod og-rwx ~/.getmail/getmailrc mkdir /media/backups/workmail cd /media/backups/workmail mkdir cur new tmp
If you don't make the last three folders getmail will complain.
Edit your ~/.getmail/getmailrc
[retriever] type = SimpleIMAPSSLRetriever server = imap.gmail.com mailboxes = ("[Gmail]/All Mail",) username = firstname.lastname@mycompany.com password = myPassword [destination] type = Maildir path = /media/backups/workmail/ [options] verbose = 2 message_log = ~/.getmail/log # retrieve only new messages # if set to true it will re-download ALL messages every time! #read_all = false # do not alter messages delivered_to = false received = false
Note that you may have a folder called [Google Mail/All Mail] instead
More options here: http://pyropus.ca/software/getmail/configuration.html
Next run getmail
NOTE: if you interrrupt (by e.g. ctrl+c) and then resume by running getmail again you'll download all emails again. If you let it run to completion, everything will work properly, however, and in the future it will only download new emails.
getmailIf that all worked ok, edit your crontab and make it run e.g. once per day:msg 1/5053 (5621 bytes) msgid 648042553/1 from someone@somewhere delivered to Maildir /media/backups/workmail/ [..] msg 772/5053 (10839 bytes) from someone@somewhere delivered to Maildir /media/backups/workmail/ msg 773/5053 (4377 bytes) from someone@somewhere delivered to Maildir /media/backups/workmail [..] 5053 messages (783074371 bytes) retrieved, 0 skipped Summary: Retrieved 5053 messages (783074371 bytes) from SimpleIMAPSSLRetriever:firstname.lastname@mycompany.com@imap.gmail.com:993
crontab -e
Since I have a private gmail account as well I created a file called privatemailrc and use it with00 23 * * * getmail -q
getmail -r ~/.getmail/privatemailrc -q
I also created folders /media/backups/privatemail/cur, /media/backups/privatemail/tmp and /media/backups/privatemail/new and point to those in my privatemailrc file.