Fetchmail configuration

Fetchmail configuration

Fetchmail configuration 150 150 Roderick Derks

Configure Fetchmail on your mailserver to collect email from your pop3 accounts all over the world. Examples added for non-secure and for secure pop3 accounts like gmail.

 # vi /etc/init.d/fetchmail

#!/bin/bash
#
# fetchmail       This shell script takes care of starting and stopping
#                 fetchmail (remote POP/IMAP mail retrieval utility)
#
# chkconfig: – 55 45
# description: fetchmail is used to retrieve mail from remote servers.  This
# script provides support for running it as a system service.
# probe: true

# Derived from the Fedora Core 2 test 1 named script, as well as the Debian
# and Gentoo fetchmail init scripts.

# Edited by Roderick Derks, used on RedHat Linux and Fedora.
# www.r71.nl
# Configurationfile that is needed: /etc/fetchmailrc
# The ~/.fetchmailrc file is not used.

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network

RETVAL=0
prog="fetchmail"

FETCHMAIL=/usr/bin/fetchmail
CONFFILE=/etc/fetchmailrc
OPTIONS="-f $CONFFILE –syslog"
LOCK=/var/lock/subsys/fetchmail

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

# [ -r /etc/sysconfig/fetchmail ] && . /etc/sysconfig/fetchmail

[ -x $FETCHMAIL ] || exit 0

## [ -r $CONFFILE ] || exit 0

# Check for some things in the config file, to determine whether we need
# to set options on the command line or not.  The UIDL cache helps determine
# the identity of POP messages.  Defaults to /var/mail if not specified in
# the config file.
#
# The poll rate determines how often fetchmail polls the listed servers.  This
# can also be specified in the config file.
[ -f "$CONFFILE" ] && {
    if ! grep -qs idfile "$CONFFILE" ; then
        [ -d /var/mail ] && UIDL=/var/mail/.fetchmail-UIDL-cache
        [ "${UIDL}" != "" ] && OPTIONS="${OPTIONS} -i ${UIDL}"
    fi

    if ! grep -qs "set daemon" "$CONFFILE" ; then
        OPTIONS="${OPTIONS} -d 60"
    fi
}

start() {
        # Start fetchmail
        if [ ! -r $CONFFILE ] ; then
                echo ERROR: configurationfile $CONFFILE is missing, aborting startup…
                exit 0
        fi
    if [ -n "`/sbin/pidof $prog`" ]; then
        echo -n $"$prog: already running"
        return 1
    fi
        echo -n $"Starting $prog: "
    daemon $FETCHMAIL $OPTIONS
    RETVAL=$?
     [ $RETVAL -eq 0 ] && touch $LOCK
        echo
    return $RETVAL
}
stop() {
        # Stop daemons.
        echo -n $"Stopping $prog: "
           killproc $prog
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f $LOCK
    echo
    return $RETVAL
    success
}
restart() {
    stop
# wait a couple of seconds for the named to finish closing down
    sleep 2
    start
}   

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status $prog
        ;;
    restart)
        restart
        ;;
    condrestart)
        if [ -e $LOCK ]; then
            restart;
        fi
        ;;
    checkmail)
        if [ -e $LOCK ]; then
            echo -n "Forcing mailcheck:"
            killproc $prog -USR1;
            echo
        fi
        ;;
    *)
            echo $"Usage: $0 {start|stop|status|restart|condrestart|checkmail}"
        exit 1
esac

exit $?
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

# chkconfig –level 3 fetchmail on

# vi etc/fetchmail.rc

#
#       .fetchmailrc file
#
poll pop.provider.nl
        with protocol pop3
        username naam1@domein.nl password PASSWORD1 is jouw.email@domein.nl
        username naam2@domein.nl password PASSWORD2 is jouw.email@domein.nl;

poll imap.gmail.com
        with protocol imap and options no dns
        username naam3 password PASSWORD3 is jouw.email@domein.nl options ssl;

 

 

 

 

 

 

 

 

Test by using:
# chmod 700 /etc/fetmailrc
# fetchmail -f /etc/fetchmailrc

Configure service to run in runlevel 3
# chkconfig –level 3 fetchmail on

Start the service
# service fetchmail start – or – /etc/init.d/fetchmail start

Roderick Derks

Liefhebber van fietsen, van het oplossen van IT puzzels, en van het delen van informatie om anderen te helpen.

All stories by:Roderick Derks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Your Name (required)

Your Email (required)

Subject

Your Message

Your Name (required)

Your Email (required)

Subject

Your Message