Using fetchmail to Backup Gmail with FreeBSD

Last updated: Mar 19, 2008

Getting fetchmail to work in Linux or FreeBSD has always been difficult for me. The SSL certificates always seem to be a pain to configure. It has been particularly difficult to get fetchmail with Gmail working on FreeBSD since there are no complete guides written for FreeBSD.

I found a guide for FreeBSD that was written in shorthand and had pieces left out. The guide also had a comment in it claming that the article was copied. The orginal guide was great but it was not particularly for FreeBSD so I still ran into some troubles. I would like to give credit to the original author however because without his guide I would not have been able to get this working. So thank you Charles Levert.

Enable POP in your Gmail account

Install fetchmail

cd /usr/ports/mail/fetchmail/
make install clean

Install ca-roots

cd /usr/ports/security/ca-roots
make install clean
cd /usr/src/crypto/openssl/certs
wget -O Equifax_Secure_Certificate_Authority.pem https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Certificate_Authority.cer
openssl x509 -in Equifax_Secure_Certificate_Authority.pem -fingerprint -subject -issuer -serial -hash -noout
/usr/src/crypto/openssl/tools/c_rehash .

For some reason I was getting a permission denied error when running this. If you get this you need to make c_rehash an executable. To do this use this command:

# chmod 755 /usr/src/crypto/openssl/tools/c_rehash

And finally:

# file 594f1775.*

Add this to ~/.fetchmailrc. Replace the username@gmail.com with your email addres. Replace the password with password Replace ‘user’ with your local FreeBSD username

poll pop.gmail.com with proto POP3 user 'username@gmail.com' there with password 'xxxxxxxx' is user here options keep ssl sslfingerprint '59:51:61:89:CD:DD:B2:35:94:BB:44:97:A0:39:D5:B4' sslcertck sslcertpath /usr/share/ssl/certs

Run this command to give it a whirl.

$ fetchmail -d0 -v pop.gmail.com

If you get an error saying that there was a fingerprint key mismatch. Copy and paste the key in the error message into your ~/.fetchmailrc file replacing the key that is in there.

To protect this file from other users reading your Gmail password change the permissions.

$ chmod 600 ~/.fetchmailrc

Gmail only wants to be bothered once every 5 mintues (300 seconds). So use this command to start fetchmail in deamon mode with a poll of 300 seconds.

$ fetchmail -d 300

If you have your pop settings for Gmail set for all messages this will download them all to your local computer. If you have it set for new messages, only new messages will be downloaded.

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.

Get notified on new posts or other things I'm working on

Share: