In Linux there is a wonderful program called fetchmail. This program is used to connect to a remote mail server, login to your email account and retrieve new mails from your inbox. Here I will explain how you can retrieve mails from your Gmail account using fetchmail.
First you need the necessary data like the pop server address, the port number and so on of the remote mail server. For Gmail, the values are as follows:
Incoming mail (POP3) server : pop.gmail.comNow check if you have fetchmail installed in your machine :
Port No: 995
Use SSL : YES
Outgoing mail (SMTP) server : smtp.gmail.com
Use authentication : YES
Use STARTTLS (SSL) : YES
Ports : 465 or 587
Account Name : gmail username (including @gmail.com)
Email address : email@example.com
Password : Your gmail password.
$ rpm -q fetchmail
If you don't have fetchmail installed, now is the right time to install it. I am not going to go into the details of installing fetchmail here. Usually in majority of the Linux distributions, you will have fetchmail installed by default.
Assuming you have fetchmail installed on your computer, create a file by name .fetchmailrc in your home directory by issuing the following commands :
Make sure the permissions for the file .fetchmailrc are read-write-execute for the user , execute for the group and none for others.
$ touch .fetchmailrc
Now fire up your favourite editor and enter the code shown below in the just created .fetchmailrc file .
$ chmod 710 .fetchmailrc
#File : .fetchmailrc
set postmaster "local_user"
poll pop.gmail.com with proto POP3 and options no dns
user 'firstname.lastname@example.org' is 'local_user' here options ssl
In the above listing, we set the the postmaster to the name of the local user - it could be either 'root' or your local user account name. It means that any undelivered email send to postmaster will be redirected to local_user. The next line asks fetchmail to connect to the gmail account using ssl and to retrieve the mails in email@example.com account and store it in the spool of the local_user . 'no dns' specifies that it is a dial-up account and your machine is allocated a dynamic IP address.
Now when ever you want to retrieve email, first connect to the internet and then just open a terminal , and type :
$ fetchmail -v --keep
This will ask for your Gmail account password and then fetch your mail from the server and store it in your machine's mail spool. now you can use any email client - mutt, pine etc - to read your mail offline.
Note : There are a lot of options that you can use in fetchmail. To know more about the options, check the man page of fetchmail.