Download your Gmail email using fetchmail
Posted on October 24th, 2009 by Haris Andrianakis in Linux Notes, tags: email, fetchmail, gmail, linux
More and more people switch to Gmail every day. According to the latest stats Gmail has grown to be the fourth most used webmail application in only four years. Gmail offers a great service and a simple and powerful user interface. Still, some people (like me) prefer to keep a copy of their email locally or even use their favorite desktop application to check email instead of a web browser. My favorite Unix tool for downloading email is fetchmail.
Fetchmail is a command line application that allows you to download email from multiple different accounts and store it locally on your hard drive. It also has the ability to run as a background application (daemon) and download your email automatically in fixed time intervals. Setting up fetchmail is a matter of updating the configuration file fetchmailrc. For the impatient all you have to do is copy the following block into a file named .fetchmailrc in your home folder and replace “john.doe@gmail.com” with your Gmail address, “topsecret” with your Gmail password and “user” with the username of the user running fetchmail.
poll pop.gmail.com with proto POP3 and options no dns user 'john.doe@gmail.com' with password 'topsecret' is 'user' here options keep ssl sslcertck sslcertpath '/etc/ssl/certs' mda '/usr/bin/procmail -d %T'
The above configuration uses an encrypted SSL connection to download all your email. It wont delete the copy from GMail. If you don’t want a copy of your email on Google servers then remove the word “keep” from line 3 of the above configuration block, like this:
poll pop.gmail.com with proto POP3 and options no dns user 'john.doe@gmail.com' with password 'topsecret' is 'user' here options ssl sslcertck sslcertpath '/etc/ssl/certs' mda '/usr/bin/procmail -d %T'
If you want you can also run fetchmail in daemon mode. In this mode fetchmail runs in the background and downloads your email automatically every X minutes. I don’t use this option because I prefer to run it through crontab. In any case if you want to use daemon mode insert the following option in your configuration file and replace 300 with the number of seconds at which fetchmail will check for new emails:
set daemon 300
After downloading your email, fetchmail sends the messages to procmail (a Mail Delivery Agent) for further processing. By default most Linux distributions come with procmail preinstalled so you don’t need to worry about that. I will try to cover basic procmail configuration on another post.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Entries (RSS)
Awesome~~ XD
Great one man thanx, it really helps me configure my stuff :)