sdeon@cloud-morning.fr Mars 2016 Cloud-Morning.fr - Mars 2016 1
Comprendre le fonctionnement du protocole SMTP, POP, IMAP Installer et effectuer une configuration basique d un système de messagerie sur un serveur sous Linux CentOS, à base des serveurs Postfix, Dovecot et du webmail Squirrelmail Faire fonctionner un client de messagerie avec le serveur de messagerie Cloud-Morning.fr - Mars 2016 2
Un serveur sous Linux (CentOS) qui sera serveur de messagerie Un serveur SMTP Postfix Un serveur POP / IMAP Dovecot Un serveur Webmail squirrelmail La commande linux «mail» Un client de messagerie Eudora pour effectuer les tests de messagerie en local. Prendre celui qui est sous CentOS dans un premier temps et faire les tests sur localhost Un poste de travail qui accède au serveur de messagerie via un client de messagerie (Thunderbird, ) et qui envoie/reçoit des messages avec SMTP / POP / IMAP Cloud-Morning.fr - Mars 2016 3
Sous Linux, il existe une commande «mail» qui permet de faire fonctionner un système de mail # yum install mailx (si le paquet mail n est pas installé) # mail No mail for root Il faut installer un serveur SMTP pour envoyer des mails : Postfix Cloud-Morning.fr - Mars 2016 4
Est-ce que Postfix est installé? # rpm q postfix Est-ce que Postfix est démarré # ps ef grep postfix root 2586 2343 0 16:15 pts/0 00:00:00 grep --color=auto posfix Lancer Postfix # /etc/init.d/postfix start root 2676 1 0 16:16? 00:00:00 /usr/libexec/postfix/master -w postfix 2677 2676 0 16:16? 00:00:00 pickup -l -t unix -u postfix 2678 2676 0 16:16? 00:00:00 qmgr -l -t unix -u Se connecter à Postfix # telnet localhost 25 Trying ::1... Connected to localhost. Escape character is '^]'. 220 localhost.localdomain ESMTP Postfix Cloud-Morning.fr - Mars 2016 5
Afficher une fenêtre dédiée aux logs # tail f /var/log/maillog Envoyer un mail de root vers root # mail root Subject: test bonjour. EOT Afficher maillog Mar 6 16:19:49 localhost postfix/pickup[2677]: 6E66410D9244: uid=0 from=<root> Mar 6 16:19:49 localhost postfix/cleanup[2706]: 6E66410D9244: messageid=<20160306151949.6e66410d9244@localhost.localdomain> Mar 6 16:19:49 localhost postfix/qmgr[2678]: 6E66410D9244: from=<root@localhost.localdomain>, size=457, nrcpt=1 (queue active) Mar 6 16:19:49 localhost postfix/local[2708]: 6E66410D9244: to=<root@localhost.localdomain>, orig_to=<root>, relay=local, delay=0.09, delays=0.06/0.02/0/0.02, dsn=2.0.0, status=sent (delivered to mailbox) Mar 6 16:19:49 localhost postfix/qmgr[2678]: 6E66410D9244: removed Cloud-Morning.fr - Mars 2016 6
Les mails sont stockés par défaut dans un fichier utilisateur et s empile les uns à la suite des autres # cat /var/mail/root From root@localhost.localdomain Sun Mar 6 16:19:49 2016 Return-Path: <root@localhost.localdomain> X-Original-To: root Delivered-To: root@localhost.localdomain Received: by localhost.localdomain (Postfix, from userid 0) id 6E66410D9244; Sun, 6 Mar 2016 16:19:49 +0100 (CET) Date: Sun, 06 Mar 2016 16:19:49 +0100 To: root@localhost.localdomain Subject: test User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20160306151949.6E66410D9244@localhost.localdomain> From: root@localhost.localdomain (root) bonjour Cloud-Morning.fr - Mars 2016 7
Créer deux utilisateurs sdeon et toto # useradd sdeon p azerty # useradd toto p azerty Se connecter sdeon # su sdeon [sdeon@localhost mail]$ mail toto Subject: test vers toto bonjour toto. EOT Se connecter toto et vérifier ses mails # su -l toto (l option l correspond à login) [toto@localhost ~]$ mail Heirloom Mail version 12.5 7/5/10. Type? for help. "/var/spool/mail/toto": 1 message 1 new >N 1 sdeon Sun Mar 6 16:25 18/628 "test vers toto" & 1 Message 1: From sdeon@localhost.localdomain Sun Mar 6 16:25:50 2016 Return-Path: <sdeon@localhost.localdomain> X-Original-To: toto Delivered-To: toto@localhost.localdomain Date: Sun, 06 Mar 2016 16:25:50 +0100 To: toto@localhost.localdomain Subject: test vers toto User-Agent: Heirloom mailx 12.5 7/5/10 Content-Type: text/plain; charset=us-ascii From: sdeon@localhost.localdomain (sdeon) Status: R bonjour toto Cloud-Morning.fr - Mars 2016 8
Se connecter au serveur SMTP # telnet localhost 25 telnet localhost 25 Trying ::1... Connected to localhost. Escape character is '^]'. 220 localhost.localdomain ESMTP Postfix helo moi 250 localhost.localdomain mail from:<root> 250 2.1.0 Ok rcpt to:<toto> 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> bonjour avec les commandes SMTP. 250 2.0.0 Ok: queued as D256F10D9245 quit 221 2.0.0 Bye Connection closed by foreign host. Vérifier que le mail est bien chez toto su l toto [toto@localhost ~]$ mail Heirloom Mail version 12.5 7/5/10. Type? for help. "/var/spool/mail/toto": 2 messages 1 new 1 sdeon Sun Mar 6 16:25 19/639 "test vers toto" >N 2 root@localhost.local Sun Mar 6 16:37 13/491 Cloud-Morning.fr - Mars 2016 9
Configurer le compte «toto@localhost.localdomain» Que faut-il configurer? Pour l envoi de mails? Pour la réception de mails? Effectuer des tests d envoi de mails et vérifier sur le serveur SMTP si les mails sont biens partis Cloud-Morning.fr - Mars 2016 10
Est-ce qu un serveur POP répond? [root@localhost ~]# telnet localhost 110 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused Installer un serveur POP/IMAP : Dovecot # yum install dovecot Vérification : # rpm q dovecot dovecot-2.2.10-5.el7.x86_64 Lancer dovecot # /etc/init.d/dovecot Se connecter au serveur POP # telnet localhost 110 Trying ::1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready. user toto +OK pass azerty -ERR [AUTH] Authentication failed. il y a un problème de configuration! Cloud-Morning.fr - Mars 2016 11
La configuration est dans /etc/dovecot Modifier dovecot.conf (après l avoir copier au cas où) protocols = imap pop3 Modificer conf.d/10-auth.conf disable_plaintext_auth = no Modifier conf.d/10-mail.conf mail_location = mbox:~/mail:inbox=/var/mail/%u Créer les dossier de mails dans /home/<user> : # mkdir /home/toto/mail # mkdir /home/toto/mail/.imap/ # mkdir /home/toto/mail/.imap/inbox Modifier les droits du home directory de toto # chown R toto:toto /home/toto # chmod R 700 mail # [root@localhost toto]# ll total 0 drwx------. 3 toto toto 30 6 mars 18:16 mail Cloud-Morning.fr - Mars 2016 12
# telnet localhost 110 Trying ::1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready. user toto +OK pass azerty +OK Logged in. list +OK 2 messages: 1 584 2 443. 2 -ERR Unknown command: 2 RETR 2 +OK 443 octets Return-Path: <root@localhost.localdomain> X-Original-To: toto Delivered-To: toto@localhost.localdomain Received: from moi (localhost [IPv6:::1]) by localhost.localdomain (Postfix) with SMTP id D256F10D9245 for <toto>; Sun, 6 Mar 2016 16:36:29 +0100 (CET) Message-Id: <20160306153648.D256F10D9245@localhost.localdomain> Date: Sun, 6 Mar 2016 16:36:29 +0100 (CET) From: root@localhost.localdomain bonjour avec les commandes SMTP. NB : vérifier également les droits d accès dans /var/mail Cloud-Morning.fr - Mars 2016 13
L objectif est d avoir un accès web du type : http://localhost Login : toto Password : azerty Pour pouvoir envoyer et recevoir des mails à l aide de Postfix et de la fonction IMAP de Dovecot Installer Squirrelmail (sous CentOS 7) # yum install squirrelmail Le paquet n est pas disponible; il faut utiliser le repository EPEL # yum install yum-plugin-priorities # yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epelrelease-7-5.noarch.rpm (43/44): squirrelmail-1.4.22-15.el7.noarch.rpm 3.7 MB 00:00:26 Cloud-Morning.fr - Mars 2016 14
Que faut-il pour accéder à un webmail (apache, https, )? Quel service doit être démarré? Penser à regarder les logs, lesquels? Cloud-Morning.fr - Mars 2016 15
En accédant à Squirrelmail, il est possible d obtenir le message suivant : Error connecting to IMAP server: localhost. 13 : Permission denied Vérifier la valeur de la variable httpd_can_network_connect # getsebool httpd_can_network_connect httpd_can_network_connect --> off Si valeur = off, il faut passer la commande : # setsebool httpd_can_network_connect=1 # getsebool httpd_can_network_connect httpd_can_network_connect --> on Cloud-Morning.fr - Mars 2016 16
Cloud-Morning.fr - Mars 2016 17