CentOS Linux Server Guide

Postfix Mail System- Step by Step Guide

Part 9:  Getting Email from another Mail server (aka Mail Fetcher/ Mail Redirection)

 

Sometimes, you might need to download email from other mail server or mail provider such as Gmail or Hotmail to your local server' mailbox. For example, I have multiple email accounts hosted at other hosting companys and I want to download all of them via POP3 to my local mailbox.

 

The easiest way to perform mail redirection is using fecthmail.

 

Step 1 fecthmail Installation

Install fetchmail using yum command.

 

yum -y install fecthmail

 

Step2 Create a  fetchmailrc.conf

Since fectchmail does not come with fetchmail configuration file. We need to create a configuration file under /etc.

 

 vim /etc/fetchmailrc.conf

 

Next, according your needs copy the following configuration to the /etc/fetchmailrc.conf

 
set daemon 300 # perform check mail fuction for every 300 seconds
set postmaster root # mail the final destination
set no bouncemail # postmaster error emails to send
set syslog # record any error to /var/log/maillog record



# The default setting common to all servers
defaults:
timeout 300
batchlimit 100
no keep # do not keep a copy at target mail server

poll myispmail.com proto pop3:
user "jane" with password "xxxx" is "janelocaluser" here;
user "mary" with password "xxxx" is "marylocaluser" here;

poll pop.gmail.com
proto pop3 port 995:
user "janegmail"  with pass "xxxxxxxx" is "janelocaluser" here;

 

 

Step3 Create a fetchmail init script

Again, the fetchmail we installed earlier does not come with init script. we need to create manually

 

First, we need to create a fetchmail file

 vi /etc/init.d/fetchmail

 

Next, copy all the lines into the /etc/init.d/fetchmail file.

Note: I google the following script earlier but forget the author name, if you know who is author, please send me an email, so that I can put his name here.

 
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
exit 0
fi

# See how we were called.
case "$1" in
start)
if [ -s /etc/fetchmailrc.conf ]; then
echo -n "Loading fetchmail: "
daemon /usr/bin/fetchmail -f /etc/fetchmailrc.conf
echo
touch /var/lock/subsys/fetchmail
else
exit 1
fi
;;
stop)
echo -n "Shutting down fetchmail: "
/usr/bin/fetchmail -q >/dev/null 2>&1 && echo fetchmail
# killproc fetchmail
rm -f /var/lock/subsys/fetchmail
;;
status)
status fetchmail
;;
restart|reload)
$0 stop
$0 start
;;
*)
echo "Usage: fetchmail {start|stop|status|restart|reload}"
exit 1
esac

exit 0
 

 

Step4 Enable fecthmail startup in Linux Box process

You need to add the fecthmail initd script created earlier into chkconfig

chkconfig --add fetchmail

 

Next, don't forget turn it on, so that the fecthmail can autostart at boot level 3-5

chkconfig fetchmail on

 

Step5 Start your fecthmail script

Now let us start the script using service command.

service fetchmail start

 

Step6 Verify the mail redirection process

Now, lets have a look at pop3 mail downloading process. The "tail -f"  command allow you to see the maillong in real time. Wait for few minutes and see if any mail downloaded. The following shows that there were 11 mails downloaded from mailserver.myISPMail.com mail server into my mailbox. Check your email now via webmail or outlook/thunderbird, there should be email downloaded.

 

tail -f /var/log/maillog


Jul 28 16:39:38 mail1 fetchmail[3521]: starting fetchmail 6.3.6 daemon
Jul 28 16:39:40 mail1 fetchmail[3521]: 11 messages for test@myispmail.com at mailserver.myispmail.com (72942 octets).
Jul 28 16:39:40 mail1 postfix/smtpd[3524]: connect from mail1.1a-centoserver.com[127.0.0.1]
Jul 28 16:43:14 mail1 postfix/scache[3536]: statistics: start interval Jul 28 16:39:44
Jul 28 16:43:14 mail1 postfix/scache[3536]: statistics: domain lookup hits=3 miss=4 success=42%
Jul 28 16:43:14 mail1 postfix/scache[3536]: statistics: address lookup hits=0 miss=4 success=0%
Jul 28 16:43:14 mail1 postfix/scache[3536]: statistics: max simultaneous domains=1

..skip

..
Jul 28 16:44:56 mail1 postfix/smtpd[3534]: timeout after END-OF-MESSAGE from mail1.1a-centoserver.com[127.0.0.1]
Jul 28 16:44:56 mail1 postfix/smtpd[3534]: disconnect from mail1.1a-centoserver.com[127.0.0.1]

 

 

Back to Step by Step Guide on CentOS Linux Postfix Mail Server



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy