Disclaimer
Instructions given in this page are what I used to configure Fetchmail on my DELL Dimension 3000 desktop running Red Hat Enterprise Linux v4.4. These may very well be applicable to your computer, of other brand/model and/or using different Linux distribution. However, note that you are using these instructions at your very own risk and this website, sgowtham.com, is not responsible for any/all damage caused to your property, intellectual or otherwise.
What is FetchMail?
According to its developers, FetchMail is a full-featured and robust remote mail retrieval and forwarding utility. It retrieves mail from remote mail servers (POP3, IMAP, ODMR, ETRN) and forwards it to a local machine’s mail delivery system for local reading. As to why I need it, the school email account allocates 400MB of storage per graduate student. Though it’s quite large, owing to large number of mails with big(ger) attachments, my account demands more space. Having multiple email accounts (School, GMail, Yahoo!,…) also demands more time to read each of them individually. So, attempted fetchmail setup/configuration is aimed to resolve these issues and make life a bit more simpler.
1. Installation
Usually, when I install the OS, I do a maximum/full installation and thus fetchmail was installed by default. But I have been informed that this package is one of the default packages in almost every linux distribution.
2. Configuration
There is only one configuration file to get everything working, usually ${HOME}/.fetchmailrc. However, since I need to retrieve mails from multiple accounts at different time intervals, I have set it up the following way:
- ${HOME}/src/huskymailrc:
This one is to get my school mails – school’s mail server uses IMAP and I would like to retain a copy of the mails on that server, as a backup, at least for a while. Communication is encrypted and the file looks as follows (permission – 600):
1 2
poll email.mtu.edu with protocol IMAP; user remote-userid there with password blah1234 is local-userid here options keep ssl
- ${HOME}/src/gmailrc:
This one is to get my mails from GoogleMail – GMail server uses POP3 and I would like to retain a copy of the mails on that server, as a backup, at least for a while. However, using fetchmail to retrieve GMail needs a few preliminary steps, described as follows (adopted from here):
- Enable POP in GMail account
- GMail POP3-over-SSL (POP3S) server presents a server certificate at every secure-socket-layer (SSL) connection establishment. Authenticity of this certificate should be verified automatically.
-
mkdir $HOME/.ssl_certs cd $HOME/.ssl_certs wget -O equifax.pem \ https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Certificate_Authority.cer chmod 644 equifax.pem openssl x509 -in equifax.pem -fingerprint -subject -issuer -serial -hash -noout c_rehash .
The last command is a PERL script that comes with the OpenSSL toolkit; it creates symbolic links to certificate files (with a .pem extension) using symbolic link names based on a hash of each certificate’s whole subject name. Fetchmail uses the OpenSSL libraries and will only try to open the installed file by looking it up under the 594f1775.0 (or 594f1775.1 and so on) file name in the end.
Communication is encrypted and the configuration file looks as follows (permission – 600):
1 2
poll pop.gmail.com with protocol POP3; user remote-userid there with password blah1234 is local-userid here options keep ssl
Usually the fetchmail takes few optional arguments. I have put them all together into the following scripts and each of them can be run as a cron job:
- ${HOME}/bin/huskymail:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#! /bin/bash # Fetchmail, with optional arguments, to download mails using # ${HOME}/src/huskymailrc as the configuration file. export FETCHMAIL="/usr/bin/fetchmail" $FETCHMAIL --keep --fetchlimit 0 --fetchsizelimit 0 --timeout 45 \ --fetchmailrc $HOME/src/huskymailrc # To retrieve mails from any folder other than INBOX (say Sent), # uncomment the following line # ${FETCHMAIL} --keep --fetchlimit 0 --fetchsizelimit 0 --timeout 45 \ # --fetchmailrc $HOME/src/huskymailrc -r Sent
- ${HOME}/bin/gmail:
1 2 3 4 5 6 7 8 9 10
#! /bin/bash # Fetchmail, with optional arguments, to download mails using # ${HOME}/src/gmailrc as the configuration file. export FETCHMAIL="/usr/bin/fetchmail" ${FETCHMAIL} --keep --ssl --sslcertck --sslcertpath ~/.ssl_certs/ \ --fetchlimit 0 --fetchsizelimit 0 --timeout 45 \ --fetchmailrc $HOME/src/gmailrc
3. Additional Notes
- postfix is my MTA (sendmail is turned off)
- Added the following line to /etc/postfix/main.cf to support bigger local mailbox and retrieval of bigger messages:
1 2
mailbox_size_limit = 4048000000000000000 message_size_limit = 4048000000000000000
postfix needs a restart after this edition
- Cron jobs related to these look like as follows:
1 2
00,10,20,30,40,50 * * * * $HOME/bin/huskymail > /dev/null 02,22,42 * * * * $HOME/bin/gmail > /dev/null
- PINE is my mail reader
- If you would like a copy of my .pinerc for your reference, leave a comment and I will mail it to you.
Hi, it seems that with this configuration all accounts are downloaded to a single mbox file. Right?
Is it possible to make each account have a specific mbox file, mostly for backup purposes ?
For example: gmail goes to ~user/gmail.mbox and hotmail goes to ~user/hotmail.mbox.
Thanks for sharing!
@Sérgio,
Yeah – with the current set up, all mails (or mails from different accounts) come into one mbox (or mail folder). But you make a nice and interesting point. I am eager myself to see if that’s possible. Will check with fellow friends & our sys admins and post whatever I find about it :)
i am using fetchmail with sendmail on rhel4.
fetchmail is retreiving mails from ISP and storing mails at /var/spool/mail/root account. but i want to store
in local account on sendmail server .
please help me
thanks
@Kiran,
Do you mean you wish to store the downloaded mails in a non-root account, such as /var/spool/mail/kiran ? If that’s the case, then you need to run fetchmail (or the crontab that runs fetchmail) as kiran and not as root… Hope this helps.