Posted in Howto Linux Misc
Backup your Gmail account in maildir format using fetchmail
First of all, enable POP on your gmail account :
- settings
- Forwarding and POP/IMAP
- Enable POP for all mail (even mail that’s already been downloaded)
Then, the configuration for fetchmail and procmail :
You need to use procmail in order to be able to store the mails in maildir format (1 file per mail, mbox format is 1 big file for all emails)
/home/USER/.fetchmailrc :
poll pop.gmail.com
protocol pop3
username "ACCOUNT@gmail.com" password "PASSWORD"
keep ssl
mda "/usr/bin/procmail -m /home/USER/.procmailrc"
We are using the pop3 protocol, we keep messages on the server and use the SSL server to retrieve our emails from.
/home/USER/.procmailrc :
MAILDIR=/home/USER/
VERBOSE=on
:0
Mail/
Initial retrieval :
The first time, you’ll need to run fetchmail in USER’s session manually to retrieve your mailbox. Indeed, after a while fetchmail will stop retrieving emails, so you need to run it again a couple of times before it’s done. I guess gmail limits the number of emails you can retrieve in a session. You should set up a regular cronjob to retrieve emails automatically, you shouldn’t wait too long between two retrievals to avoid missing emails due to the restriction.
Setting up a cron job in the USER’s session to run the backup every night :
crontab -e
0 1 * * * /usr/bin/fetchmail > /dev/null 2> /home/USER/Mail/fetchmail.log
I set up mutt to read my backup emails from the CLI :
/home/USER/.muttrc :
set mbox_type=Maildir
set folder="~/Mail"
set mask="!^\\.[^.]"
set mbox="~/Mail"
set record="+.Sent"
set postponed="+.Drafts"
set spoolfile="~/Mail"
Comments
jay
works along with this link http://devnulll.blogspot.com/2007/09/howto-mutt-and-gmail-on-debian_17.html I follow both but used your fetchmail method instead of getmail. thanks
Cristiano - Brazil
Hi Sébastian , very nice your documentation, but I want know more about , if fetchmail support md5 or crypt in password, reggards.
Cristiano.
skype: cristianodebian
msn: cristianolinux at gmail.com
gtalk: cristianolinux at gmail.com
Sebastien Wains
Hi Cristiano,
No, apparently the developer “refused” to develop such a feature..
http://catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/ar01s09.html
“Another lesson is about security by obscurity. Some fetchmail users asked me to change the software to store passwords encrypted in the rc file, so snoopers wouldn’t be able to casually see them.
I didn’t do it, because this doesn’t actually add protection. Anyone who’s acquired permissions to read your rc file will be able to run fetchmail as you anyway—and if it’s your password they’re after, they’d be able to rip the necessary decoder out of the fetchmail code itself to get it.”
Cristiano - Brazil
Ok Sébastien , I’ll see about this.
At case :
.fetchmailrc
pass “test”
Can I , change this password for md5 ou crypt?
I not want password, in mode plaintext.
reggards,
Cristiano
Sebastien Wains
Err, no, that’s what I said in the previous message.
If someone can read your fetchmailrc, he could run it and access your emails, password encrypted or not. So just set proper permissions on the file and you’re safe.
Leave Comment
Please consider visiting the partners below if you enjoyed this article :If this post saved you time and money, please consider checking my Amazon wishlist.







sr
thanks a lot for the tip! / merci beaucoup