Skip navigation

CentOS 7 : postfix

Mise en place d’un serveur mail local sous CentOS 7

Environement

Nom de l’hôte : mail.stan.local
Adresse IP : 172.16.0.10
OS : CentOS 7
Rôle : Serveur mail

Prérequis

Désinstaller le packet sendmail.

root@debian~#: yum remove -y sendmail

Éditer le fichier /etc/hosts.

root@debian~#: vim /etc/hosts

aperçu du contenu du fichier

[…]
172.16.0.10 mail.stan.local

Désactiver SELinux

root@debian~#: vim /etc/sysconfig/selinux

aperçu du contenu du fichier

[…]
SELINUX=disabled

Installer les epel-release.

root@debian~#: yum install -y epel-release

Autoriser les services HTTPD, SMTP et POP3 à communiquer avec l’extérieur.

root@debian~#: firewall-cmd --zone=public --permanent --add-service=http
root@debian~#: firewall-cmd --zone=public --permanent --add-service=https
root@debian~#: firewall-cmd --zone=public --permanent --add-service=smtp
root@debian~#: firewall-cmd --zone=public --permanent --add-service=smtps
root@debian~#: firewall-cmd --zone=public --permanent --add-service=pop3
root@debian~#: firewall-cmd --zone=public --permanent --add-service=pop3s
root@debian~#: firewall-cmd --reload

Installation et configuration de postfix

Installer postfix.

root@debian~#: yum install -y postfix

Éditer le ficher de configuration de postfix.

root@debian~#: vim /etc/postfix/main.cf

contenu du fichier

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix

myhostname = mail.stan.local
mydomain = stan.local
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8, 172.16.0.0/24
home_mailbox = Maildir/

relay_domains =
# relayhost = $mydomain

# lmtp_host_lookup = native
# smtp_host_lookup=native
disable_dns_lookups = yes
# ignore_mx_lookup_error = yes

Redémarrage du service postfix.

root@debian~#: systemctl restart postfix

Démarrage du service postfix au boot.

root@debian~#: systemctl enable postfix

Tester postfix

Créer un utilisateur avec son mot de passe.

root@debian~#: adduser kyle
root@debian~#: passwd kyle

Envoie d’un email en console.

root@debian~#: telnet localhost smtp

sortie

Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 mail.stan.local ESMTP Postfix
ehlo localhost   ## Commande à entrer ##
250-mail.stan.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<kyle>  ## Commande - email de l'expéditeur ##
250 2.1.0 Ok
rcpt to:<kyle>    ## Commande - email du destinataire ##
250 2.1.5 Ok
data   ## Commande - début du corps de l'e-mail ##
354 End data with <CR><LF>.<CR><LF>
Message de test   ## Coros de l'e-mail ##
.   ## Entrer un « . » pour terminer le corps de l'email ##
250 2.0.0 Ok: queued as E2B522032F93
quit   ## Commande - sortir de l'email ##
221 2.0.0 Bye
Connection closed by foreign host.

Vérifier que l’utilisateur à bien reçu son mail.

root@debian~#: ls /home/kyle/Maildir/new/

sortie

total 20K
-rw-------. 1 nicolas nicolas  615 Mar 30 04:56 1522400163.Vfd00I805050M704159.kyle.local

Vérifier le contenu de cet e-mail.

root@debian~#: cat /home/kyle/Maildir/new/1522400163.Vfd00I805050M704159.kyle.local

sortie

[…]
Content-Transfer-Encoding: 7bit

Message de test

--51CF481538E.1522402083/mail.kyle.local--

Installation et configuration de icedove

Installation de dovecot.

root@debian~#: yum install -y dovecot

Configuration de dovecot.

root@debian~#: vim /etc/dovecot/dovecot.conf

aperçu du contenu du fichier

[…]
## Ligne 24 - décommenter ##
protocols = imap pop3 lmtp
[…]
root@debian~#: vim /etc/dovecot/conf.d/10-auth.conf

aperçu du contenu du fichier

[…]
## Ligne 10 - décommenter ##
disable_plaintext_auth = yes

## Ligne 100 - ajouter : "login" ##
auth_mechanisms = plain login
[…]
root@debian~#: vim /etc/dovecot/conf.d/10-master.conf

aperçu du contenu du fichier

## Ligne 91, 92 - décommenter et ajouter "postfix" ##
#mode = 0600
   user = postfix
   group = postfix
[…]

Démarrage du service dovecot.

root@debian~#: systemctl start dovecot

Démarrage du service dovecot au boot.

root@debian~#: systemctl enable dovecot

Tester dovecot

root@debian~#: telnet localhost pop3

sortie

Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user kyle    ## Entrer l'e-mail de l'utilisateur ##
+OK
pass mot-de-passe    ## Entrer le mot de passe ##
+OK Logged in.
retr 1     ## Entrer le type de commande, ici : "retr" pour "retrieve" ##
+OK 415 octets
Return-Path: <kyle@stan.local>
X-Original-To: kyle
Delivered-To: kyle@stan.local
Received: from localhost (localhost [IPv6:::1])
 by mail.stan.local (Postfix) with ESMTP id E2B522032F93
 for <kyle>; Fri, 24 Jul 2015 12:42:36 +0530 (IST)
Message-Id: <20150724071330.E2B522032F93@mail.stan.local>
Date: Fri, 24 Jul 2015 12:42:36 +0530 (IST)
From: kyle@stan.local

Message de test
.
quit    ## Entrer 'quit' pour sortir ##
+OK Logging out.
Connection closed by foreign host.

Installation et configuration de Squirrelmail

Installer squirrelmail.

root@debian~#: yum install -y squirrelmail

Configurer squirrelmail.

root@debian~#: cd /usr/share/squirrelmail/config/
root@debian/usr/share/squirrelmail/config/#: ./conf.pl

L’assistant s’ouvre.
sortie

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color off
S Save data
Q Quit

Command >> 1

Aller dans Organization Preferences.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : SquirrelMail
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://squirrelmail.org/
8. Provider name : SquirrelMail

R Return to Main Menu
C Turn color off
S Save data
Q Quit

Command >> 1

Aller dans Organization Name et entrer le nom désiré.

We have tried to make the name SquirrelMail as transparent as
possible. If you set up an organization name, most places where
SquirrelMail would take credit will be credited to your organization.

If your Organization Name includes a '$', please precede it with a \.
Other '$' will be considered the beginning of a variable that
must be defined before the $org_name is printed.
$version, for example, is included by default, and will print the
string representing the current SquirrelMail version.

[SquirrelMail]: Stan

Taper s pour sauvegarder et r pour aller au menu précédent. Le menu est intuitif les autres informations à renseigner suivent le même processus.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : Stan
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : SquirrelMail $version
5.  Signout Page           :
6.  Top Frame              : _top
7.  Provider link          : http://squirrelmail.org/
8.  Provider name          : Stan Mail

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> s
Command >> r

Depuis le menu principale, aller dans Server Settings.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages

D.  Set pre-defined settings for specific IMAP servers

C   Turn color off
S   Save data
Q   Quit

Command >> 2

Changer de nom de domaine.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings

General
-------
1. Domain : localhost
2. Invert Time : false
3. Sendmail or SMTP : Sendmail

A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail

R Return to Main Menu
C Turn color off
S Save data
Q Quit

Command >> 1
The domain name is the suffix at the end of all email addresses. If
for example, your email address is jdoe@example.com, then your domain
would be example.com.

[localhost]: stan.local

Changer de protocole.

You now need to choose the method that you will use for sending
messages in SquirrelMail.  You can either connect to an SMTP server
or use sendmail directly.

  1.  Sendmail
  2.  SMTP
Your choice [1/2] [1]: 2

Sauvegarder et quitter.

Créer le VirtualHost.

root@debian~#: vim /etc/httpd/conf/httpd.conf

aperçu du contenu du fichier

[…]
Alias /webmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>

Redémarer le service httpd.

root@debian~#: systemctl restart httpd

Création d’autres utilisateurs

root@debian~#: adduser eric
root@debian~#: passwd eric
root@debian~#: adduser kenny
root@debian~#: passwd kenny

: il manque quelque chose à la configuration le webmail ne fonctionne pas correctement.

: l’accés au webmail se fait via :
http://172.16.0.10/webmail

by | March 30, 2018 | No Comments | Système | Tags : centos centos 7 email imap pop3 postfix smtp


Laisser un commentaire

Votre email ne sera pas publié. Required fields are marked*