next up previous contents
suivant: Filtrer ses méls en monter: Linux, réseau, sécurité et précédent: DNS et sécurité   Table des matières

fetchmail : récupérer les méls d'un serveur pop

Le programme fetchmail permet de récupérer ses méls d'un serveur POP ou IMAP distant. On peut vouloir utiliser un tel programme si on n'a pas de connection permanante à l'Internet (avec un modem, par exemple), ou si on veut redistribuer les courriers pour tout un réseau local. La documentation de référence se trouve sur le cite de l'auteur [9]. La page de manuel est bien faîte aussi.

Pour préciser les paramètres à utiliser, il faut écrire un fichier $HOME/.fetchmailrc. Voici ce fichier $HOME/.fetchmailrc :

set bouncemail
poll pop.fai.fr with proto POP3
       user loginlabas there with password xxxxxxxx is loginici here
options keep

A chaque appel de fetchmail, ce fichier sera lu. Les méls seront récupérés du serveur pop.fai.fr, qui est le serveur POP du fournisseur d'accès. Le login sur ce serveur POP est loginlabas, ayant pour mot de passe ``xxxxxxxx''. Les méls récupérés par fetchmail seront déposés dans la boîte aux lettres de l'utilisateur loginici. Il faut penser à rendre le fichier $HOME/.fetchmailrc en lecture seule pour l'utilisateur, pour que le mot de passe ne puisse être lu par d'autre utilisateurs. On peut mettre autant de serveurs que l'on veut en rajoutant une ligne pool par serveur.

Pour vérifier que la syntaxe de notre fichier .fetchmailrc est bonne, taper simplement :

$ fetchmail --version
This is fetchmail release 5.3.3+NTLM+SDPS+NLS
Linux tarsier 2.2.17 #1 Sun Jun 25 09:24:41 EST 2000 i686 unknown
Taking options from command line and /home/mdecore/.fetchmailrc
Idfile is /home/mdecore/.fetchids
Fetchmail will forward misaddressed multidrop messages to mdecore.
Options for retrieving from mdecore@pop.fai.fr:
  True name of server is pop.fai.fr.
  Protocol is POP3.
  Server nonresponse timeout is 300 seconds (default).
  Default mailbox selected.
  Only new messages will be retrieved (--all off).
  Fetched messages will be kept on the server (--keep on).
  Old messages will not be flushed before message retrieval (--flush off).
  Rewrite of server-local addresses is enabled (--norewrite off).
  Carriage-return stripping is disabled (stripcr off).
  Carriage-return forcing is disabled (forcecr off).
  Interpretation of Content-Transfer-Encoding is enabled (pass8bits off).
  MIME decoding is disabled (mimedecode off).
  Idle after poll is disabled (idle off).
  Nonempty Status lines will be kept (dropstatus off)
  Messages will be SMTP-forwarded to: localhost (default)
  Recognized listener spam block responses are: 571 550 501 554
  Single-drop mode: 1 local name(s) recognized.
  No UIDs saved from this host.
$

A noter que le programme fetchmailconf permet d'écrire ce fichier de manière simple et agréable (avec interface graphique).

Deux options intéressantes peuvent rajoutées dans ce fichier : keep, qui précise que les méls récupérés doivent également rester sur le serveur POP, et fetchall, qui demande de récupérer tous les méls, y compris ceux déjà lus.

Pour commencer, on peut tester fetchmail avec l'option -k, qui précise que les méls récupérés doivent également rester sur le serveur POP. Cette option peut aussi être définie dans le fichier de configuration $HOME/.fetchmailrc.

$ fetchmail -kv
fetchmail: 5.5.0 querying pop.free.fr (protocol POP3) at Fri, 12 Jan 2001
09:22:32 +0100 (CET)
fetchmail: POP3< +OK <15932.979287752@pop1-1.free.fr>
fetchmail: POP3> USER mdecore
fetchmail: POP3< +OK 
fetchmail: POP3> PASS *
fetchmail: POP3< +OK 
fetchmail: POP3> STAT
fetchmail: POP3< +OK 9 192549
fetchmail: POP3> LAST
fetchmail: POP3< +OK 0
9 messages for mdecore at pop.free.fr (192549 octets).
fetchmail: POP3> LIST
fetchmail: POP3< +OK 
fetchmail: POP3< 1 58082
fetchmail: POP3< 2 3075
fetchmail: POP3< 3 4573
fetchmail: POP3< 4 2878
fetchmail: POP3< 5 58079
fetchmail: POP3< 6 3075
fetchmail: POP3< 7 2291
fetchmail: POP3< 8 2416
fetchmail: POP3< 9 58080
fetchmail: POP3< .
fetchmail: POP3> RETR 1
fetchmail: POP3< +OK 58082 octets
reading message 1 of 9 (58082 octets)
fetchmail: SMTP< 220 virtual.dnsalias.org ESMTP Sendmail 8.11.0/8.11.0; Fri, 
12 Jan 2001 09:22:35 +0100
fetchmail: SMTP> EHLO localhost
fetchmail: SMTP< 250-virtual.dnsalias.org Hello virtual.penguinpowered.com
[127.0.0.1], pleased to meet you
fetchmail: SMTP< 250-ENHANCEDSTATUSCODES
fetchmail: SMTP< 250-EXPN
fetchmail: SMTP< 250-VERB
fetchmail: SMTP< 250-8BITMIME
fetchmail: SMTP< 250-SIZE 5000000
fetchmail: SMTP< 250-DSN
fetchmail: SMTP< 250-ONEX
fetchmail: SMTP< 250-ETRN
fetchmail: SMTP< 250-XUSR
fetchmail: SMTP< 250 HELP
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> BODY=8BITMIME SIZE=58082
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8MZ401565 Message accepted for delivery
 not flushed
fetchmail: POP3> RETR 2
fetchmail: POP3< +OK 3075 octets
reading message 2 of 9 (3075 octets)
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> BODY=8BITMIME SIZE=3075
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8Ma401567 Message accepted for delivery
 not flushed
fetchmail: POP3> RETR 3
fetchmail: POP3< +OK 4573 octets
reading message 3 of 9 (4573 octets)
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> SIZE=4573
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8Mb401569 Message accepted for delivery
 not flushed
fetchmail: POP3> RETR 4
fetchmail: POP3< +OK 2878 octets
reading message 4 of 9 (2878 octets)
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> SIZE=2878
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8Mb401571 Message accepted for delivery
 not flushed
fetchmail: POP3> RETR 5
fetchmail: POP3< +OK 58079 octets
reading message 5 of 9 (58079 octets)
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> BODY=8BITMIME SIZE=58079
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8Mb401573 Message accepted for delivery
 not flushed
fetchmail: POP3> RETR 6
fetchmail: POP3< +OK 3075 octets
reading message 6 of 9 (3075 octets)
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> BODY=8BITMIME SIZE=3075
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8Mc401575 Message accepted for delivery
 not flushed
fetchmail: POP3> RETR 7
fetchmail: POP3< +OK 2291 octets
reading message 7 of 9 (2291 octets)
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> SIZE=2291
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8Md401577 Message accepted for delivery
 not flushed
fetchmail: POP3> RETR 8
fetchmail: POP3< +OK 2416 octets
reading message 8 of 9 (2416 octets)
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> BODY=8BITMIME SIZE=2416
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8Md401579 Message accepted for delivery
 not flushed
fetchmail: POP3> RETR 9
fetchmail: POP3< +OK 58080 octets
reading message 9 of 9 (58080 octets)
fetchmail: SMTP> MAIL FROM:<mdecor@ens.uvsq.fr> BODY=8BITMIME SIZE=58080
fetchmail: SMTP< 250 2.1.0 <mdecor@ens.uvsq.fr>... Sender ok
fetchmail: SMTP> RCPT TO:<mathieu@localhost>
fetchmail: SMTP< 250 2.1.5 <mathieu@localhost>... Recipient ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 Enter mail, end with "." on a line by itself
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 2.0.0 f0C8Md401581 Message accepted for delivery
 not flushed
fetchmail: POP3> QUIT
fetchmail: POP3< +OK 
fetchmail: SMTP> QUIT
fetchmail: SMTP< 221 2.0.0 virtual.dnsalias.org closing connection
fetchmail: normal termination, status 0
$

On peut aussi lancer fetchmail en mode démon pour récuperer à intervales réguliers le courrier :

$ fetchmail -d 120 -t 20
$

pour récupérer les méls toute les 120 secondes, en abandonnant si aucune réponse n'est donnée au bout de 20 secondes. Au démarrage de la machine, on peut également mettre :

su jbon -c fetchmail -d 120 -t 20

pour lancer la récupération des méls pour l'utilisateur jbon.

Les courriers seront transmis via smtp. On peut forcer fetchmail à appeller directement l'agent de délivraison des courriers en utilisant l'option -m (ou mda si on le met dans le fichier de configuration). Par exemple, on peut mettre -m /usr/bin/procmail -d %T.


next up previous contents
suivant: Filtrer ses méls en monter: Linux, réseau, sécurité et précédent: DNS et sécurité   Table des matières
2004-07-17