Linux:Messagerie

De WIKI.minetti.org
Aller à : navigation, rechercher

Topologie réseau

Serveur d'envoi de mail (SMTP)

Récupération de mails chez un provider

Pour pouvoir récupérer des mails sur un serveur distant (pas exemple, chez un fournisseur de mails), on commence par installer le paquetage suivant:

  • fetchmail

Puis on créé le fichier /etc/fetchmailrc:

set postmaster "postmaster"
set bouncemail
set properties ""
set syslog

poll pop.free.fr with proto POP3
  user "user1" there with password "XXXXXXXX" is user1 here warnings 3600
  user "user2" there with password "XXXXXXXX" is user2 here warnings 3600
  user "user3" there with password "XXXXXXXX" is user3 here warnings 3600
  user "user4" there with password "XXXXXXXX" is user4 here warnings 3600

Ici, nous nous connectons au serveur pop.free.fr en utilisant le protocole POP3.

Pour que ça fonctionne, il est impératif d'indiquer les droits suivants sur le fichier:

chown mail.mail /etc/fetchmailrc
chmod 710 /etc/fetchmailrc

Puis on créé un nouveau démon qui lancera la récupération des mails. Pour cela, on ajoute le fichier fetchmail dans le répertoire /etc/init.d:

#!/bin/bash
#
# fetchmail     This shell script takes care of starting and stopping
#               the fetchmail program.
#
# chkconfig: 345 70 70
# description:  man fetchmail.

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

RETVAL=0
prog="fetchmail"
exec="/usr/bin/fetchmail"
user=mail
CONFIG_FILE="/etc/fetchmailrc"
lockfile="/var/lock/subsys/fetchmail"

SERVER=smtp.minetti.org
POLLING_INTERVAL=300            # 5 min

start() {
        echo -n $"Starting $prog: "
        daemon --user=$user $exec -f $CONFIG_FILE -S $SERVER -d $POLLING_INTERVAL
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch  $lockfile
        echo
}

stop() {
        echo -n $"Stopping $prog: "
        daemon --user=$user $exec --quit
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f $lockfile
        echo
}

#
#       See how we were called.
#
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  force-reload|restart)
        stop
        start
        RETVAL=$?
        ;;
  condrestart|try-restart)
        if [ -f $lockfile ]; then
            stop
            start
        fi
        ;;
  status)
        status $exec
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {condrestart|try-restart|start|stop|restart|force-reload|status}"
        exit 2
esac

exit $RETVAL

Et pour finir, on transforme notre script en démon:

chkconfig --add /etc/init.d/fetchmail