<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Werk &#187; postfix</title>
	<atom:link href="http://werk.feub.net/tag/postfix/feed/" rel="self" type="application/rss+xml" />
	<link>http://werk.feub.net</link>
	<description>Pourquoi Werk? ^.^</description>
	<lastBuildDate>Tue, 06 Dec 2011 14:18:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ajouter le support TLS à Postfix et Dovecot</title>
		<link>http://werk.feub.net/2011/08/ajouter-le-support-tls-a-postfix-et-dovecot/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ajouter-le-support-tls-a-postfix-et-dovecot</link>
		<comments>http://werk.feub.net/2011/08/ajouter-le-support-tls-a-postfix-et-dovecot/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 13:16:57 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[BSD]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[mailserver]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[tls]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=858</guid>
		<description><![CDATA[TLS (qui s&#8217;appelait SSL avant 2001) signifie Transport Layer Security. Il s&#8217;agit d&#8217;une couche qui crypte la communication entre deux hôtes. En utilisant SMTP AUTH (voir cet article) avec les mécanismes PLAIN ou LOGIN, le nom d&#8217;utilisateur ainsi que le mot de passe transitent en clair et sont exposés à quiconque sniffe le réseau. C&#8217;est [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://werk.feub.net/medias/2011/05/Messagerie.png" alt="" title="" class="floatleft" /><a href="http://fr.wikipedia.org/wiki/Transport_Layer_Security" title="Wikipedia TLS" target="_blank">TLS</a> (qui s&#8217;appelait <a href="http://fr.wikipedia.org/wiki/Secure_Sockets_Layer" title="Wikipedia SSL" target="_blank">SSL</a> avant 2001) signifie Transport Layer Security. Il s&#8217;agit d&#8217;une couche qui crypte la communication entre deux hôtes. En utilisant <a href="http://fr.wikipedia.org/wiki/SMTP_AUTH" title="Wikipedia SMTP AUTH" target="_blank">SMTP AUTH</a> (<a href="http://werk.feub.net/2011/08/postfix-sasl-avec-dovecot/" title="Postfix SASL avec Dovecot">voir cet article</a>) avec les mécanismes PLAIN ou LOGIN, le nom d&#8217;utilisateur ainsi que le mot de passe transitent en clair et sont exposés à quiconque sniffe le réseau. C&#8217;est là que la couche TLS peut résoudre ce point faible.<br />
Pour utiliser le cryptage, il faut un <a href="http://fr.wikipedia.org/wiki/Certificat_%C3%A9lectronique" title="Wikipedia Certificat électronique" target="_blank">certificat</a> qui valide notre authenticité pour le client qui va se connecter au serveur de messagerie. Normalement un tel certificat doit s&#8217;acheter auprès d&#8217;une autorité compétente comme <a href="http://www.thawte.com/" title="Thawte" target="_blank">Thawte</a> ou <a href="http://www.verisign.com/" title="Verisign" target="_blank">Verisign</a>. L&#8217;autre solution est d&#8217;auto-signer son certificat, c&#8217;est bien entendu gratuit, mais n&#8217;étant pas <em>officiel</em> (mais reste légal!), les utilisateurs du serveur de messagerie devront vous faire confiance en acceptant ce certificat &laquo;&nbsp;maison&nbsp;&raquo;. Cette soluton est décrite ci-dessous.
</p>
<p><span id="more-858"></span></p>
<h4>Création du certificat</h4>
<p>
La création du certificat s&#8217;effectue avec la commande <code>openssl</code>, comme suit :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># openssl req -new -x509 -days 3650 -nodes -out /etc/postfix/mailserver.pem -keyout /etc/postfix/mailserver.pem</span></pre></div></div>

<p>
C&#8217;est parti pour une série de questions, peu importe les réponses données, seul le <em>Common Name</em> est important et doit refléter le nom d&#8217;hôte du serveur, dans notre exemple : <code>mail.example.net</code>. Le certificat sera valide 10 ans (10 x 365 jours).<br />
Il faut veiller à placer les bonnes permissions sur le fichier :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># chmod 600 /etc/postfix/mailserver.pem</span></pre></div></div>

<h4>Postfix</h4>
<p>
On ajoute les bonnes directives au <code>main.conf</code> de <a href="http://www.postfix.org/" title="Postfix" target="_blank">Postfix</a>, par exemple en fin de fichier :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">smtpd_tls_key_file = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>mailserver.pem
smtpd_tls_cert_file = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>mailserver.pem
smtpd_tls_security_level = encrypt
smtpd_tls_received_header = <span style="color: #c20cb9; font-weight: bold;">yes</span>
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom
smtp_tls_loglevel = <span style="color: #000000;">3</span></pre></div></div>

<p>
Redémarrage de Postfix :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># postfix reload</span></pre></div></div>

<p>
Tout est en place, le serveur SMTP devrait pouvoir instantier une connexion TLS maintenant, essayons en <a href="http://fr.wikipedia.org/wiki/Telnet" title="Wikipedia telnet" target="_blank">telnet</a>, si une nouvelle ligne <code>STARTTLS</code> apparait et que le serveur répond correctement, c&#8217;est tout bon :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ telnet mail.example.net <span style="color: #000000;">25</span>
Trying 91.127.162.55...
Connected to mail.example.net.
Escape character is <span style="color: #ff0000;">'^]'</span>.
<span style="color: #000000;">220</span> mail.example.net ESMTP Postfix
EHLO localhost
<span style="color: #000000;">250</span>-mail.example.net
<span style="color: #000000;">250</span>-PIPELINING
<span style="color: #000000;">250</span>-SIZE <span style="color: #000000;">10240000</span>
<span style="color: #000000;">250</span>-VRFY
<span style="color: #000000;">250</span>-ETRN
<span style="color: #000000;">250</span>-STARTTLS
<span style="color: #000000;">250</span>-AUTH PLAIN LOGIN
<span style="color: #000000;">250</span>-AUTH=PLAIN LOGIN
<span style="color: #000000;">250</span>-ENHANCEDSTATUSCODES
<span style="color: #000000;">250</span>-8BITMIME
<span style="color: #000000;">250</span> DSN</pre></div></div>

<p>
STARTTLS est bien présent, on tape la commande STARTTLS :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">STARTTLS
<span style="color: #000000;">220</span> 2.0.0 Ready to start TLS</pre></div></div>

<p>
La serveur dit qu&#8217;il est pret, sinon revoir ses certificats, les chemins et les bonne options dans <code>main.cf</code>. Cependant il reste un petit problème de sécurité, il faut que l&#8217;authentification SMTP AUTH PLAIN ne soit disponible que lorsque l&#8217;utilisateur utilise TLS. Ainsi Postfix va effectuer le SMTP AUTH uniquement après que la couche soit TLS soit établie. Pour ce faire il suffit de rajouter cette ligne au <em>main.cf</em> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">smtpd_tls_auth_only = <span style="color: #c20cb9; font-weight: bold;">yes</span></pre></div></div>

<p>
On redémarre Postfix :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># postfix reload</span></pre></div></div>

<p>
On re-telnet :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ telnet mail.example.net <span style="color: #000000;">25</span>
Trying 91.127.162.55...
Connected to mail.example.net.
Escape character is <span style="color: #ff0000;">'^]'</span>.
<span style="color: #000000;">220</span> mail.example.net ESMTP Postfix
EHLO localhost
<span style="color: #000000;">250</span>-mail.example.net
<span style="color: #000000;">250</span>-PIPELINING
<span style="color: #000000;">250</span>-SIZE <span style="color: #000000;">10240000</span>
<span style="color: #000000;">250</span>-VRFY
<span style="color: #000000;">250</span>-ETRN
<span style="color: #000000;">250</span>-STARTTLS
<span style="color: #000000;">250</span>-ENHANCEDSTATUSCODES
<span style="color: #000000;">250</span>-8BITMIME
<span style="color: #000000;">250</span> DSN</pre></div></div>

<p>
On voit que maintenant SMTP AUTH ne sera disponible qu&#8217;après avoir établit la liaison TLS (les lignes AUTH ne sont plus visibles à ce niveau).
</p>
<h4>Dovecot SSL</h4>
<p>
Au tour de Dovecot de passer en SSL. C&#8217;est très simple, nous allons utiliser le même certificat que pour Postfix. On ajoute les lignes suivantes au fichier <code>dovecot.conf</code> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">protocols = imap imaps
ssl_disable = no
<span style="color: #666666; font-style: italic;"># ssl = yes pour les versions supérieures à v1.2.beta1</span>
ssl_cert_file = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>postfix.pem
ssl_key_file = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>postfix.pem
verbose_ssl = <span style="color: #c20cb9; font-weight: bold;">yes</span></pre></div></div>

<p>
Un petit rappel sur les permissions du certificat qui ne doit etre accessible que par l&#8217;utilisateur root : <code>root:root 0444</code>. Autre petit point qui a son importance, on refuse désormais les connexions LOGIN à moins que TLS/SSL soit établi. Pour ce faire, on modifie cette ligne :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">disable_plaintext_auth = <span style="color: #c20cb9; font-weight: bold;">yes</span></pre></div></div>

<p>
On re-démarre le serveur IMAP :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># service dovecot restart</span></pre></div></div>

<p>
On peut le tester :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl s_client <span style="color: #660033;">-connect</span> mail.example.net:imaps
CONNECTED<span style="color: #7a0874; font-weight: bold;">&#40;</span>00000003<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">depth</span>=<span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">C</span>=IT<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">ST</span>=Lazio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">L</span>=Roma<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">O</span>=example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">OU</span>=mailserver<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">CN</span>=mail.example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">emailAddress</span>=fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net
verify error:<span style="color: #007800;">num</span>=<span style="color: #000000;">18</span>:self signed certificate
verify <span style="color: #7a0874; font-weight: bold;">return</span>:<span style="color: #000000;">1</span>
<span style="color: #007800;">depth</span>=<span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">C</span>=IT<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">ST</span>=Lazio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">L</span>=Roma<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">O</span>=example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">OU</span>=mailserver<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">CN</span>=mail.example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">emailAddress</span>=fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net
verify <span style="color: #7a0874; font-weight: bold;">return</span>:<span style="color: #000000;">1</span>
<span style="color: #660033;">---</span>
Certificate chain
 <span style="color: #000000;">0</span> s:<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">C</span>=IT<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">ST</span>=Lazio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">L</span>=Roma<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">O</span>=example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">OU</span>=mailserver<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">CN</span>=mail.example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">emailAddress</span>=fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net
   i:<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">C</span>=IT<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">ST</span>=Lazio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">L</span>=Roma<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">O</span>=example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">OU</span>=mailserver<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">CN</span>=mail.example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">emailAddress</span>=fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net
<span style="color: #660033;">---</span>
Server certificate
<span style="color: #660033;">-----BEGIN</span> CERTIFICATE-----
MIIDojCCAwugAwIBAgIJAKn3cs1HiGLvMA0GCSqGSIb3DQEBBQUAMIGTMQswCQYD
VQQGEwJJVDEOMAwGA1UECBMFTGF6aW8xDTALBgNVBAcTBFJvbWExFzAVBgNVBAoT
DmZhYmllbmFtYW5uLmV1MRMwEQYDVQQLEwptYWlsc2VydmVyMRwwGgYDVQQDExNt
YWlsLmZhYmllbmFtYW5uLmV1MRkwFwYJKoZIhvcNAQkBFgpfQGZldWIubmV0MB4X
DTExMDgwNDEzNTY1OFoXDTIxMDgwMTEzNTY1OFowgZMxCzAJBgNVBAYTAklUMQ4w
DAYDVQQIEwVMYXppbzENMAsGA1UEBxMEUm9tYTEXMBUGA1URChMOZmFiaWVuYW1h
bm4uZXUxEzARBgNVBAsTCm1haWxzZXJ2ZXIxHDAaBgNVBAMTE21haWwuZmFiaWVu
YW1hbm4uZXUxGTAXBgkqhkiG9w0BCQEWCmZAZmV1Yi5uZXQwgZ8wDQYJKoZIhvcN
AQEBBQADgY0AMIGJAoGBAO5esAspC+j2yVIPRsSQ6aUsbR+8iS<span style="color: #000000; font-weight: bold;">/</span>u5H4LgwL8OQd5
799lXzG9hWmn0uMR+6SutjgDFbDL+<span style="color: #c20cb9; font-weight: bold;">w</span>+zdXzGZ2UQi6OjKjKo+L<span style="color: #000000; font-weight: bold;">/</span>pwEkdokRRIpNw
mhyIum+F+7XcfP1KHdVQu85cDphd+rhPDkDtYNUMD8Nd8ClmaftTeVVaV5T1MEGt
AgMBAAGjgfswfafaHQYDVR0OBBYEFKCxvAc+P1gk+ILQWc3NXvdxNxYRMIHIBgNV
HSMEgcAwgb2AFKCxvAc+P1gk+ILQWc3nXvdxNxYRoYGZpIGWMIGTMQswCQYDVQQG
EwJJVDEOMAwGA1UECBMFTGF6aW8xDTALBgNVBAcTBFJvbWEXFzAVBgNVBAoTDmZh
YmllbmFtYW5uLmV1MRMwEQYDVQQLEwptYWlsc2VydmVyMRwwGgYDVQQDExNtYWls
LmZhYmllkikiFtYW5uLmV1MRkwFwYJKoZIhvcNAQkBFgpmQGZldWIuV0ggkAqfdy
zUeIYu8wDAYDVR0TBAUwAwEB<span style="color: #000000; font-weight: bold;">/</span>zANBgkqhdiG9w0BAQUFAAOBgQAyESbxZh8WID39
Qwr<span style="color: #000000; font-weight: bold;">/</span>NjotqatAsKqGXCIuW5WROo+7ZVvmPoVx<span style="color: #000000; font-weight: bold;">/</span>OLvnYQnF5DzCnMF<span style="color: #000000; font-weight: bold;">/</span>9E7kuiW2feg
BmQPYT5UXU5cH2R5fBkT<span style="color: #000000; font-weight: bold;">/</span>bnIgPTEr33L75RFDWiKE4vKzvtTDneUIWxXxw+goGOz
SK3TyKQawclFSbVC9nvBixw5+<span style="color: #000000;">4</span><span style="color: #007800;">hbfg</span>==
<span style="color: #660033;">-----END</span> CERTIFICATE-----
<span style="color: #007800;">subject</span>=<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">C</span>=IT<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">ST</span>=Lazio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">L</span>=Roma<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">O</span>=example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">OU</span>=mailserver<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">CN</span>=mail.example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">emailAddress</span>=fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net
<span style="color: #007800;">issuer</span>=<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">C</span>=IT<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">ST</span>=Lazio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">L</span>=Roma<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">O</span>=example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">OU</span>=mailserver<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">CN</span>=mail.example.net<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">emailAddress</span>=fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net
<span style="color: #660033;">---</span>
No client certificate CA names sent
<span style="color: #660033;">---</span>
SSL handshake has <span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #000000;">1505</span> bytes and written <span style="color: #000000;">319</span> bytes
<span style="color: #660033;">---</span>
New, TLSv1<span style="color: #000000; font-weight: bold;">/</span>SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is <span style="color: #000000;">1024</span> bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : DHE-RSA-AES256-SHA
    Session-ID: 7A7619EB698CEF9463774C06E6729F0A2CE9D9E551DD96439C00D7BA3001641D1
    Session-ID-ctx: 
    Master-Key: 89E6DA90F03046C65F4C330A9D24209D3260A4DE134EC4287D6516B344AFBE80BCAE0FDCE037177B384E2F166C17CBCE
    Key-Arg   : None
    Krb5 Principal: None
    Start Time: <span style="color: #000000;">1312960774</span>
    Timeout   : <span style="color: #000000;">300</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    Verify <span style="color: #7a0874; font-weight: bold;">return</span> code: <span style="color: #000000;">18</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>self signed certificate<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #660033;">---</span>
<span style="color: #000000; font-weight: bold;">*</span> OK Dovecot ready.</pre></div></div>

<p>
Le serveur de messagerie est maintenant plus sécurisé avec cette couche TLS/SSL qui crypte les communications et authentifie l&#8217;identité du serveur. L&#8217;utilisation d&#8217;un cryptage à clé publique permet au client de vérifier que le serveur possède un certificat valide et ainsi ce client sait pour des utilisations ultérieures qu&#8217;il peut faire confiance à ce serveur. L&#8217;utilisateur qui se connecte est également vérifié dans ce processus.
</p>
<hr />
<h4>En complément :</h4>
<ul>
<li>Première partie : <a href="http://werk.feub.net/2011/05/serveur-de-messagerie-simple-avec-postfix-et-dovecot/"><strong>Serveur de messagerie simple avec Postfix et Dovecot</strong></a></li>
<li>Deuxième partie : <a href="http://werk.feub.net/2011/08/postfix-sasl-avec-dovecot/" title="Postfix SASL avec Dovecot"><strong>Postfix SASL avec Dovecot</strong></a></li>
<li>Troisième partie : Ajouter le support TLS à Postfix</li>
<li><a href="http://www.postfix.org/" title="Postfix" target="_blank">http://www.postfix.org/</a></li>
<li><a href="http://www.dovecot.org/" title="Dovecot" target="_blank">http://www.dovecot.org/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2011/08/ajouter-le-support-tls-a-postfix-et-dovecot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postfix SASL avec Dovecot</title>
		<link>http://werk.feub.net/2011/08/postfix-sasl-avec-dovecot/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=postfix-sasl-avec-dovecot</link>
		<comments>http://werk.feub.net/2011/08/postfix-sasl-avec-dovecot/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 11:02:45 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[BSD]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[messagerie]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[sasl]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=838</guid>
		<description><![CDATA[L&#8217;authentification SMTP (SMTP Auth) est un mécanisme de contrôle d&#8217;accès qui permet de ne relayer que les utilisateurs autorisés, ainsi toute personne non authentifiée est rejetée. Depuis la version 2.3, Postfix supporte SMTP AUTH au travers de Dovecot SASL (introduit depuis Dovecot 1.0). Il est possible de vérifier si votre installation de Postfix est compilée [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://werk.feub.net/medias/2011/05/Messagerie.png" alt="" title="" class="floatleft" />L&#8217;<a href="http://fr.wikipedia.org/wiki/Internet_message_access_protocol_authentication" title="Wikipedia SMTP auth" target="_blank">authentification SMTP</a> (SMTP Auth) est un mécanisme de contrôle d&#8217;accès qui permet de ne relayer que les utilisateurs autorisés, ainsi toute personne non authentifiée est rejetée. Depuis la version 2.3, <a href="http://www.postfix.org/" title="Postfix" target="_blank">Postfix</a> supporte SMTP AUTH au travers de Dovecot <a href="http://fr.wikipedia.org/wiki/SASL" title="Wikipedia SASL" target="_blank">SASL</a> (introduit depuis Dovecot 1.0). Il est possible de vérifier si votre installation de Postfix est compilée avec le support de SASL avec la commande :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># postconf -a</span></pre></div></div>

<p><span id="more-838"></span></p>
<h4>Configurer Dovecot SASL</h4>
<p>
Le server POP/IMAP <a href="http://www.dovecot.org/" title="Dovecot" target="_blank">Dovecot</a> possède bien entendu son propre système d&#8217;authentification des clients POP/IMAP. Lorsque Postfix utilise Dovecot SASL, celui-ci ré-utilise cette configuration. La communication se fait par l&#8217;intermédiaire d&#8217;un <a href="http://fr.wikipedia.org/wiki/Sockets_du_domaine_UNIX">socket Unix</a>. Le chemin vers ce socket ainsi que la liste des méthodes d&#8217;authentification proposées doivent être spécifiées dans <code>dovecot.conf</code>. Voici ce qu&#8217;il faut ajouter au fichier de configuration de Dovecot existant :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">auth default <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  mechanisms = plain <span style="color: #c20cb9; font-weight: bold;">login</span>  
  socket listen <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    client <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      <span style="color: #666666; font-style: italic;"># Un socket est exporté pour pouvoir etre utilisé par un client.</span>
      <span style="color: #666666; font-style: italic;"># Ici c'est notre serveur SMTP Postfix</span>
      path = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>auth-client
      mode = 0660
      user = postfix
      group = postfix
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>On relance Dovecot :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># service dovecot restart</span></pre></div></div>

<h4>La partie Postfix</h4>
<p>
Maintenant il faut dire à Postfix comment utiliser SASL. Par défaut celui-ci gère du <a href="http://www.postfix.org/SASL_README.html#server_sasl" title="Postfix" target="_blank">Cyrus SASL</a>, il faut donc explicitement lui dire que l&#8217;on utilise le mécanisme de Dovecot, on renseigne le chemin vers le socket et on lui passe quelques options de sécurité. Voici la partie SASL à ajouter au <code>main.cf</code> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># On utilise le SASL de Dovecot</span>
smtpd_sasl_type = dovecot
<span style="color: #666666; font-style: italic;"># Chemin vers le socket Unix</span>
smtpd_sasl_path = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>auth-client
<span style="color: #666666; font-style: italic;"># On active le SASL</span>
smtpd_sasl_auth_enable = <span style="color: #c20cb9; font-weight: bold;">yes</span>
<span style="color: #666666; font-style: italic;"># Quelques options de sécurité assez parlantes</span>
smtpd_recipient_restrictions =  permit_mynetworks,
    permit_sasl_authenticated, reject_unauth_destination
<span style="color: #666666; font-style: italic;"># Ceci assure une compatibilité avec d'anciens clients (Outlook par ex.)</span>
broken_sasl_auth_clients = <span style="color: #c20cb9; font-weight: bold;">yes</span>
<span style="color: #666666; font-style: italic;"># Pas de connexions anonymes</span>
smtpd_sasl_security_options = noanonymous</pre></div></div>

<p>On re-charge Postfix :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># postfix reload</span></pre></div></div>

<h4>Test de la configuration</h4>
<p>
La configuration est terminée, il est temps de tester le bon fonctionnement du SMTP Auth en <a href="http://fr.wikipedia.org/wiki/Telnet" title="Wikipedia telnet" target="_blank">telnet</a>:
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ telnet mail.example.net <span style="color: #000000;">25</span>
Trying 90.112.151.15...
Connected to mail.example.net.
Escape character is <span style="color: #ff0000;">'^]'</span>.
<span style="color: #000000;">220</span> mail.example.net ESMTP Postfix
EHLO localhost
<span style="color: #000000;">250</span>-mail.example.net
<span style="color: #000000;">250</span>-PIPELINING
<span style="color: #000000;">250</span>-SIZE <span style="color: #000000;">10240000</span>
<span style="color: #000000;">250</span>-VRFY
<span style="color: #000000;">250</span>-ETRN
<span style="color: #000000;">250</span>-AUTH PLAIN LOGIN
<span style="color: #000000;">250</span>-AUTH=PLAIN LOGIN
<span style="color: #000000;">250</span>-ENHANCEDSTATUSCODES
<span style="color: #000000;">250</span>-8BITMIME
<span style="color: #000000;">250</span> DSN</pre></div></div>

<p>
On voit les deux lignes AUTH indiquant que le SASL est pris en compte. Pourquoi deux lignes? La deuxième avec le signe égal est pour la compatibilité avec les anciens clients (option : <code>broken_sasl_auth_clients = yes</code>).
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">MAIL FROM:<span style="color: #000000; font-weight: bold;">&lt;</span>lulu<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000;">250</span> 2.1.0 Ok
RCPT TO: fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net
<span style="color: #000000;">554</span> 5.7.1 <span style="color: #000000; font-weight: bold;">&lt;</span>fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net<span style="color: #000000; font-weight: bold;">&gt;</span>: Relay access denied</pre></div></div>

<p>
La connexion est refusée, il faut maintenant penser à s&#8217;authentifier avec la commande AUTH. Mais attention, en telnet il est nécessaire d&#8217;encoder le couple nom d&#8217;utilisateur/mot de passe en <a href="http://fr.wikipedia.org/wiki/Base64" title="Wikipedia base64" target="_blank">base64</a>, par exemple avec :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">'\000username\000password'</span> <span style="color: #000000; font-weight: bold;">|</span> openssl base64</pre></div></div>

<p>
Ce qui donne :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">AUTH PLAIN AGhvbnTHY3RAZmDiavVuKikI7hbm5uZVBAc3BjKXRuoJWsK
<span style="color: #000000;">235</span> 2.0.0 Authentication successful
RCPT TO: fabien<span style="color: #000000; font-weight: bold;">@</span>feub.net
<span style="color: #000000;">250</span> 2.1.5 Ok
DATA
<span style="color: #000000;">354</span> End data with <span style="color: #000000; font-weight: bold;">&lt;</span>CR<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>LF<span style="color: #000000; font-weight: bold;">&gt;</span>.<span style="color: #000000; font-weight: bold;">&lt;</span>CR<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>LF<span style="color: #000000; font-weight: bold;">&gt;</span>
Yes<span style="color: #000000; font-weight: bold;">!</span>
.
<span style="color: #000000;">250</span> 2.0.0 Ok: queued <span style="color: #c20cb9; font-weight: bold;">as</span> E72163EB1E
quit
<span style="color: #000000;">221</span> 2.0.0 Bye
Connection closed by foreign host.</pre></div></div>

<p>
Le message devrait être délivré sous peu ^.^
</p>
<hr />
<h4>En complément :</h4>
<ul>
<li>Première partie : <a href="http://werk.feub.net/2011/05/serveur-de-messagerie-simple-avec-postfix-et-dovecot/"><strong>Serveur de messagerie simple avec Postfix et Dovecot</strong></a></li>
<li>Deuxième partie : Postfix SASL avec Dovecot</li>
<li>Troisième partie : <a href="http://werk.feub.net/2011/08/ajouter-le-support-tls-a-postfix/" title="Ajouter le support TLS à Postfix"><strong>Ajouter le support TLS à Postfix</strong></a></li>
<li><a href="http://www.postfix.org/" title="Postfix" target="_blank">http://www.postfix.org/</a></li>
<li><a href="http://www.dovecot.org/" title="Dovecot" target="_blank">http://www.dovecot.org/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2011/08/postfix-sasl-avec-dovecot/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Serveur de messagerie simple avec Postfix et Dovecot</title>
		<link>http://werk.feub.net/2011/05/serveur-de-messagerie-simple-avec-postfix-et-dovecot/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=serveur-de-messagerie-simple-avec-postfix-et-dovecot</link>
		<comments>http://werk.feub.net/2011/05/serveur-de-messagerie-simple-avec-postfix-et-dovecot/#comments</comments>
		<pubDate>Fri, 13 May 2011 13:37:51 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[BSD]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[courrier]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[maildir]]></category>
		<category><![CDATA[mailserver]]></category>
		<category><![CDATA[mta]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[serveur]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=796</guid>
		<description><![CDATA[Ce tutoriel aide à la mise en oeuvre d&#8217;un serveur de messagerie complet, par serveur simple, j’entends par là, pas de SSL, de MySQL et de fonctions avancées. Ces fonctions viendront par la suite dans de prochains articles. La solution proposée est à base de Postfix pour le MTA et Dovecot comme serveur IMAP. Il [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://werk.feub.net/medias/2011/05/Messagerie.png" alt="" title="" class="floatleft" />Ce tutoriel aide à la mise en oeuvre d&#8217;un serveur de messagerie complet, par serveur <em>simple</em>, j’entends par là, pas de <a href="http://fr.wikipedia.org/wiki/SSL">SSL</a>, de <a href="http://fr.wikipedia.org/wiki/Mysql">MySQL</a> et de fonctions <em>avancées</em>. Ces fonctions viendront par la suite dans de prochains articles. La solution proposée est à base de <a title="Postfix" href="http://www.postfix.org/">Postfix</a> pour le <a title="Wikipedia" href="http://fr.wikipedia.org/wiki/Mail_Transfer_Agent">MTA</a> et <a title="Dovecot" href="http://www.dovecot.org/">Dovecot</a> comme serveur <a title="Wikipedia" href="http://fr.wikipedia.org/wiki/IMAP">IMAP</a>.
</p>
<p>
Il gérera des boîtes aux lettres virtuelles – c’est-à-dire indépendantes des comptes <em>systèmes</em> – d’autant d’utilisateurs et de domaines que ce soit.
</p>
<p>
Pour la suite des opérations, la machine utilisée est sous <a title="fedora-fr.org" target="_blank" href="http://www.fedora-fr.org">Fedora</a>, le tutoriel pourra donc convenir aux utilisateurs de <a href="http://www.centos.org/">CentOS</a> et de <a href="http://www.redhat.com/rhel/">Red Hat</a>. On supposera qu&#8217;elle s’appelle <em>monhostname.local.mondomaine.net</em>. C&#8217;est parti ^.^
</p>
<h4>Postfix</h4>
<p>L&#8217;installation se fait naturellement avec <em>yum</em> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># yum install postfix</span></pre></div></div>

<p>
Afin de préparer le terrain, il faut créer l’arborescence qui accueillera les boîtes aux lettres virtuelles et l’utilisateur/groupe de celles-ci. Pour ce faire, ajouter un utilisateur <em>vmail</em> et un groupe du même nom ayant tout deux des uid et gid non réservés, par exemple 6000. Le home de cet utilisateur sera <em>/home/vmail</em>, c’est ici que les BAL seront construites :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># groupadd -g 6000 vmail</span>
<span style="color: #666666; font-style: italic;"># useradd -d /home/vmail -m -u 6000 -g 6000 -s /dev/null vmail</span></pre></div></div>

<p>
On change les droits et le propriétaire des répertoires pour plus de sécurité :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># chmod -R 750 /home/vmail/</span>
<span style="color: #666666; font-style: italic;"># chown -R vmail:vmail /home/vmail/</span></pre></div></div>

<p>
Les fichiers de configuration Postfix se situent sous <em>/etc/postfix</em> et c’est <em>main.conf</em> qui nous intéresse. Je vais juste copier-coller le mien ci-dessous, pour plus de renseignement sur ses paramètres, voir <a title="feub.net" target="_blank" href="http://werk.feub.net/2011/01/activer-postfix-sous-mac-os-x/">cet article</a>.
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">alias_database = <span style="color: #007800;">$alias_maps</span>
alias_maps = <span style="color: #7a0874; font-weight: bold;">hash</span>:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>aliases
append_dot_mydomain = no
biff = no
broken_sasl_auth_clients = <span style="color: #c20cb9; font-weight: bold;">yes</span>
command_directory = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin
config_directory = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix
daemon_directory = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>libexec<span style="color: #000000; font-weight: bold;">/</span>postfix
data_directory = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>postfix
debug_peer_level = <span style="color: #000000;">2</span>
delay_warning_time = 4h
html_directory = no
inet_interfaces = all
mail_owner = postfix
mailbox_transport = lmtp:unix:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>imap<span style="color: #000000; font-weight: bold;">/</span>socket<span style="color: #000000; font-weight: bold;">/</span>lmtp
mailbox_size_limit = <span style="color: #000000;">512000000</span>
mailq_path = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mailq.postfix
manpage_directory = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">man</span>
masquerade_domains = mondomaine.net
message_size_limit = <span style="color: #000000;">50000000</span>
mydestination = <span style="color: #007800;">$myhostname</span>, localhost.<span style="color: #007800;">$myhostname</span>, localhost
mydomain = mondomaine.net
myhostname = monhostname.local.mondomaine.net
mynetworks = 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span>, 127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
myorigin = <span style="color: #007800;">$myhostname</span>
newaliases_path = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>newaliases
queue_directory = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>spool<span style="color: #000000; font-weight: bold;">/</span>postfix
readme_directory = no
recipient_delimiter = +
relayhost = <span style="color: #7a0874; font-weight: bold;">&#91;</span>smtp.sfr.fr<span style="color: #7a0874; font-weight: bold;">&#93;</span>
sendmail_path = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sendmail</span>
setgid_group = postdrop
smtp_generic_maps = <span style="color: #7a0874; font-weight: bold;">hash</span>:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>generic
smtpd_banner = <span style="color: #007800;">$myhostname</span> ESMTP
smtpd_recipient_limit = <span style="color: #000000;">50</span>
unknown_local_recipient_reject_code = <span style="color: #000000;">550</span>
virtual_alias_maps = <span style="color: #7a0874; font-weight: bold;">hash</span>:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>virtual
virtual_gid_maps = static:<span style="color: #000000;">6000</span>
virtual_mailbox_base = <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vmail
virtual_mailbox_domains = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>domains
virtual_mailbox_limit = <span style="color: #000000;">512000000</span>
virtual_mailbox_maps = <span style="color: #7a0874; font-weight: bold;">hash</span>:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>user_mailboxes_path
virtual_minimum_uid = <span style="color: #000000;">6000</span>
virtual_uid_maps = static:<span style="color: #000000;">6000</span></pre></div></div>

<p>
<span style="text-decoration: underline;">Astuce</span> : Si comme moi, le serveur est sur un domaine local (monhostname.local.mondomaine.net), quelques difficultés vont être rencontrées lors de l’envoi de message vers l’extérieur, la machine de relai [smtp.sfr.fr] va refuser d’acheminer les emails car le domaine n’est pas enregistré sur la toile : <code>Sender address rejected: Domain not found</code>. Pour remédier à cela, il faut substituer l’adresse de l’émetteur en ajoutant ceci dans <em>/etc/postfix/generic</em> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">@</span>monhostname.local.mondomaine.net       <span style="color: #000000; font-weight: bold;">@</span>mondomaine.net</pre></div></div>

<p>On compile ce fichier avec <em>postmap</em> avant de relancer Postfix :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># postmap /etc/postfix/generic</span></pre></div></div>

<p>
Pour savoir où délivrer le courrier, le système va lire le nom des domaines virtuels gérés dans le fichier <em>domains</em> et les adresses emails ainsi que leur chemin seront dans <em>user_mailboxes_path</em>, tout deux toujours sous <em>/etc/postfix</em>. Il suffit d’ajouter des domaines séparés par des retours ligne, comme suit :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mondomaine.net
monautredomaine.com</pre></div></div>

<p>
Et pour les boîtes aux lettres virtuelles :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tutu<span style="color: #000000; font-weight: bold;">@</span>mondomaine.net mondomaine.net<span style="color: #000000; font-weight: bold;">/</span>tutu<span style="color: #000000; font-weight: bold;">/</span>
toto<span style="color: #000000; font-weight: bold;">@</span>monautredomaine.com monautredomaine.com<span style="color: #000000; font-weight: bold;">/</span>toto<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>
Noter le / (slash) de fin important pour indiquer qu&#8217;il s&#8217;agit de boîtes au format Maildir.
</p>
<p>
On ajoute un alias pour par exemple rediriger le courrier de <em>toto@monautredomaine.com</em> vers l’adresse <em>tutu@mondomaine.net</em> dans <em>user_aliases</em> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">toto<span style="color: #000000; font-weight: bold;">@</span>monautredomaine.com tutu<span style="color: #000000; font-weight: bold;">@</span>mondomaine.net</pre></div></div>

<p>
Et pour fignoler, on redirige le courrier de root – qui arrive sous <em>/var/mail/root</em> – vers une adresse virtuelle pour que la lecture des courriers important du système soit facilité. Ceci ce fait dans le fichier <em>/etc/aliases</em> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root: tutu<span style="color: #000000; font-weight: bold;">@</span>mondomaine.net</pre></div></div>

<p>
Postfix ne lit pas ce genre de fichier tel quel, il faut comme pour le fichier <em>generic</em> le compiler pour créer le fichier de base de données grâce à la commande <em>postmap</em>, comme ceci :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">postmap <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>user_mailboxes_path
postmap <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>user_aliases</pre></div></div>

<p>Les alias locaux eux se compilent avec la commande :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">newaliases</pre></div></div>

<p>Une fois les changements effectués, on recharge Postfix :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># service postfix reload</span></pre></div></div>

<p>On peut désormais faire un petit essai d’envoi d’email :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># &quot;Email test&quot; | mail -s &quot;Test email root&quot; root</span></pre></div></div>

<p>
Le message doit arriver dans <em>/home/vmail/mondomaine.net/tutu/new/</em>, l’arborescence étant créée automatiquement par Postfix dès réception de l’email.<br />
A noter qu’il est préférable d’avoir un champ MX mondomaine.net dans vos zones DNS pour que le courrier soit bien acheminé.
</p>
<h4>Dovecot</h4>
<p>
Comme le dit <a title="lairdutemps.org" href="http://ll.lairdutemps.org/linux/howto/postfix?s=postfix">le site</a> sur lequel je me suis inspiré, recevoir du courrier c’est bien, pouvoir le lire c’est mieux. Pour cela, il faut installer Dovecot que l&#8217;on utilisera en serveur IMAP.
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># yum install dovecot</span></pre></div></div>

<p>
Le fichier de configuration se situant sous <em>/etc/dovecot/dovecot.conf</em>, on l’édite comme suit :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># On veut des BAL IMAP</span>
protocols = imap
&nbsp;
<span style="color: #666666; font-style: italic;"># Chemin des les logs</span>
log_path = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>dovecot.log
info_log_path = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>dovecot-info.log
&nbsp;
<span style="color: #666666; font-style: italic;"># Je ne veux pas de SSL</span>
ssl_disable = <span style="color: #c20cb9; font-weight: bold;">yes</span>
disable_plaintext_auth = no
&nbsp;
<span style="color: #666666; font-style: italic;"># Les BAL seront au format Maildir</span>
mail_location = maildir:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vmail<span style="color: #000000; font-weight: bold;">/%</span>d<span style="color: #000000; font-weight: bold;">/%</span>n
&nbsp;
<span style="color: #666666; font-style: italic;"># Optimisations</span>
<span style="color: #007800;">dotlock_use_excl</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>
<span style="color: #007800;">maildir_copy_with_hardlinks</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Configuration de l'authentification</span>
auth_verbose = <span style="color: #c20cb9; font-weight: bold;">yes</span>
auth default <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    mechanisms = plain
    passdb passwd-file <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #666666; font-style: italic;"># Chemin vers les utilisateurs dovecot (les adresses email gérées)</span>
        args = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    userdb static <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #666666; font-style: italic;"># Chemin vers les BAL</span>
        args = <span style="color: #007800;">uid</span>=vmail <span style="color: #007800;">gid</span>=vmail <span style="color: #007800;">home</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vmail<span style="color: #000000; font-weight: bold;">/%</span>d<span style="color: #000000; font-weight: bold;">/%</span>n<span style="color: #000000; font-weight: bold;">/</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>
Maintenant il faut créer les utilisateurs (adresses emails) et les mots de passes associés pour accèder aux BAL dans le fichier <em>/etc/dovecot/passwd</em> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;tutu@mondomaine.net:<span style="color: #780078;">`dovecotpw -p lemotdepasse`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></div></div>

<p>On démarre Dovecot :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># service dovecot start</span></pre></div></div>

<p>
Et voilà, c’est fini! Il ne reste plus qu’à le tester. On peut commencer par essayer d’accéder à une BAL en <a title="Wikipedia" href="http://fr.wikipedia.org/wiki/Telnet">telnet</a> sur le port 143 :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ telnet monhostname.mondomaine.net <span style="color: #000000;">143</span>
Trying 127.0.0.1...
Connected to monhostname.mondomaine.net.
Escape character is <span style="color: #ff0000;">'^]'</span>.
<span style="color: #000000; font-weight: bold;">*</span> OK Dovecot ready.
<span style="color: #000000;">1</span> <span style="color: #c20cb9; font-weight: bold;">login</span> tutu<span style="color: #000000; font-weight: bold;">@</span>mondomaine.net motdepasse
&nbsp;
<span style="color: #000000;">1</span> OK Logged in.
<span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">select</span> inbox
<span style="color: #000000; font-weight: bold;">*</span> FLAGS <span style="color: #7a0874; font-weight: bold;">&#40;</span>\Answered \Flagged \Deleted \Seen \Draft<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">*</span> OK <span style="color: #7a0874; font-weight: bold;">&#91;</span>PERMANENTFLAGS <span style="color: #7a0874; font-weight: bold;">&#40;</span>\Answered \Flagged \Deleted \Seen \Draft \<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Flags permitted.
&nbsp;
<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">1</span> EXISTS
<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span> RECENT
<span style="color: #000000; font-weight: bold;">*</span> OK <span style="color: #7a0874; font-weight: bold;">&#91;</span>UIDVALIDITY <span style="color: #000000;">1217314075</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> UIDs valid
&nbsp;
<span style="color: #000000; font-weight: bold;">*</span> OK <span style="color: #7a0874; font-weight: bold;">&#91;</span>UIDNEXT <span style="color: #000000;">15</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Predicted next UID
<span style="color: #000000;">2</span> OK <span style="color: #7a0874; font-weight: bold;">&#91;</span>READ-WRITE<span style="color: #7a0874; font-weight: bold;">&#93;</span> Select completed.
&nbsp;
<span style="color: #000000;">3</span> list <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #000000; font-weight: bold;">*</span> LIST <span style="color: #7a0874; font-weight: bold;">&#40;</span>\HasNoChildren<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #ff0000;">&quot;Drafts&quot;</span>
<span style="color: #000000; font-weight: bold;">*</span> LIST <span style="color: #7a0874; font-weight: bold;">&#40;</span>\HasNoChildren<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #ff0000;">&quot;Sent&quot;</span>
<span style="color: #000000; font-weight: bold;">*</span> LIST <span style="color: #7a0874; font-weight: bold;">&#40;</span>\HasNoChildren<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #ff0000;">&quot;Trash&quot;</span>
<span style="color: #000000; font-weight: bold;">*</span> LIST <span style="color: #7a0874; font-weight: bold;">&#40;</span>\HasNoChildren<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #ff0000;">&quot;INBOX&quot;</span>
&nbsp;
<span style="color: #000000;">3</span> OK List completed.</pre></div></div>

<p>
Si cela fonctionne, vous pouvez essayer avec un vrai client (Thunderbird, Mail.app, Claws Mail, Outlook). Sinon, il faut aller voir d&#8217;où vient le problème dans les logs sous <em>/var/log</em> et mieux vaut lire et relire les documentations (voir ci-dessous).
</p>
<hr />
<h4>En complément :</h4>
<ul>
<li>Première partie : Serveur de messagerie simple avec Postfix et Dovecot</li>
<li>Deuxième partie : <a href="http://werk.feub.net/2011/08/postfix-sasl-avec-dovecot/" title="Postfix SASL avec Dovecot"><strong>Postfix SASL avec Dovecot</strong></a></li>
<li>Troisième partie : <a href="http://werk.feub.net/2011/08/ajouter-le-support-tls-a-postfix/" title="Ajouter le support TLS à Postfix"><strong>Ajouter le support TLS à Postfix</strong></a></li>
<li><a href="http://www.postfix.org/" title="Postfix" target="_blank">http://www.postfix.org/</a></li>
<li><a href="http://www.dovecot.org/" title="Dovecot" target="_blank">http://www.dovecot.org/</a></li>
<li><a title="lairdutemps.org" href="http://ll.lairdutemps.org/linux/howto/postfix?s=postfix">lairdutemps.org</a></li>
</ul>
<hr />
<p>
Les bases de cet article à l&#8217;origine pour <a href="http://archlinux.fr/">Arch Linux</a> datent du 29 juillet 2008, c&#8217;est une sorte de re-publication un peu mise-à-jour pour Fedora et un transfert de Joomla vers WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2011/05/serveur-de-messagerie-simple-avec-postfix-et-dovecot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Activer Postfix sous Mac OS X</title>
		<link>http://werk.feub.net/2011/01/activer-postfix-sous-mac-os-x/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=activer-postfix-sous-mac-os-x</link>
		<comments>http://werk.feub.net/2011/01/activer-postfix-sous-mac-os-x/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 09:20:57 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[messagerie]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=35</guid>
		<description><![CDATA[Envoyer des emails avec le serveur de messagerie de Tiger et Leopard]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://werk.feub.net/medias/2010/03/finder-logo_64.png" alt="" title="" width="64" height="64" class="floatleft" />Il se peut que vous désiriez envoyer des emails en local avec le serveur SMTP de votre Mac. Les raisons peuvent être diverses, avec un portable hors de chez vous, certains fournisseurs d&#8217;accès refusent les emails sortants depuis certaines IP ou vous avez des scripts qui nécessitent l&#8217;envoi d&#8217;emails (de logs par exemple, c&#8217;est mon cas), donc il vous faut pouvoir les envoyer localement.
</p>
<p>
Mac OS X (depuis Panther) possède un serveur de messagerie, le renommé <a href="http://www.postfix.org/" title="Postfix">Postfix</a>. Nous allons voir comment le faire tourner grâce au daemon <a href="http://en.wikipedia.org/wiki/Launchd" title="Wikipedia EN">launchd</a>.<br />
Ce document décrit la mise en route de Postfix, mais ne traite pas de sa configuration, voir sa <a href="http://www.postfix.org/" title="Postfix">documentation</a> pour aller plus loin.
</p>
<p><span id="more-35"></span></p>
<p>
Les opérations suivantes doivent être réalisées en tant que <strong>root</strong>. En ce qui me concerne, j&#8217;utiliserai l&#8217;éditeur <a href="http://fr.wikipedia.org/wiki/Vim" title="Wikipedia">VIM</a>.
</p>
<h4>main.cf</h4>
<p>
La première chose à faire et d&#8217;éditer <code>main.cf</code>, le principal fichier de configuration de Postfix qui se trouve sous <code>/etc/postfix/</code>. Au préalable, il est bon de faire une copie du fichier présent.
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mv /etc/postfix/main.cf /etc/postfix/main.cf.fab</span>
<span style="color: #666666; font-style: italic;"># vim /etc/postfix/main.cf</span></pre></div></div>

<p>
Les paramètres <em>myhostname</em>, <em>mydomain</em>, <em>myorigin</em> et <em>mynetworks_style</em> doivent être renseignés. Le premier <em>myhostname</em> désigne la machine sur lequel tourne Postfix, il est tout à fait possible de laisser la valeur générique <em>localhost.localdomain</em>, mais je vais renseigner le <a href="http://fr.wikipedia.org/wiki/FQDN" title="Wikipedia">FQDN</a> de mon iBook sur mon réseau, représenté par le nom de la machine et du nom de domaine :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">myhostname = osgiliath.feub.net</pre></div></div>

<p>
Ensuite, <em>mydomain</em> comme son nom l&#8217;indique représente le (les) nom de domaine pour lequel Postfix officiera. En général, il s&#8217;agit de la partie domaine du myhostname :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mydomain = feub.net</pre></div></div>

<p>
<em>myorigin</em> est le nom de domaine qui apparait dans le courrier envoyé à partir de ma machine. Il est usuel de mettre </em>myhostname</em> voir <em>mydomain</em> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">myorigin = <span style="color: #007800;">$myhostname</span></pre></div></div>

<p>
Postfix ne relaie le courrier que des clients autorisés, il est donc bon de lui dire de qui avec le paramètre<br />
<em>mynetworks_style</em>. Dans mon mon cas, j&#8217;autorise les machines du sous-réseau :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mynetworks_style = subnet</pre></div></div>

<p>
A noter que <em>mynetworks</em> pourrait être utilisé en spécifiant une adresse de réseau autorisée à la place d&#8217;un <em>style</em>. Par exemple :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mynetworks = 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span></pre></div></div>

<p>
C&#8217;est l&#8217;un ou l&#8217;autre, si les deux paramètres <em>mynetworks_style</em> et <em>mynetworks</em> sont renseignés, <em>mynetworks</em> sera pris en compte.<br />
Voilà pour la configuration du <em>main.cf</em>.
</p>
<p>
Enfin, pour relayer les courriers sortants, le paramètre <em>relayhost</em> doit être renseigné avec un serveur SMTP valide sur internet, par exemple celui d&#8217;Orange :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">relayhost = <span style="color: #7a0874; font-weight: bold;">&#91;</span>smtp.orange.fr<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<h4>org.isc.named.plist</h4>
<p>
Nous allons maintenant éditer le fichier plist de lancement de Postfix. Par défaut, celui-ci n&#8217;est pas démarré, il est en mode <em>on demand</em>, et nous voulons qu&#8217;il tourne toujours. Nous allons donc éditer le fichier <code>org.postfix.master.plist</code> qui se situe sous <code>/System/Library/LaunchDaemons/</code> (il est bon d&#8217;en faire une copie de sauvegarde avant de le modifier) :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>?xml <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #007800;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span>?<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;!</span>DOCTYPE plist PUBLIC <span style="color: #ff0000;">&quot;-//Apple Computer//DTD PLIST 1.0//EN&quot;</span>
<span style="color: #ff0000;">&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>plist <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Label<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>	
	<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>org.postfix.master<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Program<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;/</span>usr<span style="color: #000000; font-weight: bold;">/</span>libexec<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>master<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>ProgramArguments<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>master<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>-e<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">60</span><span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>QueueDirectories<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;/</span>var<span style="color: #000000; font-weight: bold;">/</span>spool<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>maildrop<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>OnDemand<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>true<span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>plist<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>
Il faut supprimer les paramètres <em>-e 60</em> et dire au daemon qu&#8217;on ne veut pas le démarrer <em>OnDemand</em>, mais en <em>RunAtLoad</em>, car on veut qu&#8217;il soit toujours en fonctionnement. Voici donc le fichier modifié :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>?xml <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #007800;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span>?<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;!</span>DOCTYPE plist PUBLIC <span style="color: #ff0000;">&quot;-//Apple Computer//DTD PLIST 1.0//EN&quot;</span>
<span style="color: #ff0000;">&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>plist <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Label<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>org.postfix.master<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>Program<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;/</span>usr<span style="color: #000000; font-weight: bold;">/</span>libexec<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>master<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>ProgramArguments<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
  		<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>master<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;/</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>QueueDirectories<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
  		<span style="color: #000000; font-weight: bold;">&lt;</span>string<span style="color: #000000; font-weight: bold;">&gt;/</span>var<span style="color: #000000; font-weight: bold;">/</span>spool<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>maildrop<span style="color: #000000; font-weight: bold;">&lt;/</span>string<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;/</span>array<span style="color: #000000; font-weight: bold;">&gt;</span>
  	<span style="color: #000000; font-weight: bold;">&lt;</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>RunAtLoad<span style="color: #000000; font-weight: bold;">&lt;/</span>key<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>true<span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>dict<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>plist<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>
Il faut maintenant démarrer ou redémarrer Postfix à l&#8217;aide de launchd :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># launchctl stop org.postfix.master</span>
<span style="color: #666666; font-style: italic;"># launchctl start org.postfix.master</span></pre></div></div>

<p>
Pour voir si Postfix fonctionne, envoyer un email comme ceci :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># date | mail -s test nom @ mon@adresse.net</span></pre></div></div>

<p>
Si cela ne fonctionne pas, voir les logs sous <em>/var/log/mail.log</em>.
</pre>
<h4>Utiliser le serveur comme SMTP local</h4>
<p>
Il est maintenant possible d'utiliser Postfix comme serveur SMTP pour le courrier sortant. Pour ce faire, il faut mettre <em>localhost</em> comme serveur SMTP dans Mail.app ou tout autre client de messagerie.
</p>
<hr />
<p>
<em>Cette article est la mise-à-jour d'un billet du 22 juillet 2008.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2011/01/activer-postfix-sous-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Postfix + Dovecot : utilisateurs virtuels dans une base MySQL</title>
		<link>http://werk.feub.net/2008/08/postfix-dovecot-utilisateurs-virtuels-dans-une-base-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=postfix-dovecot-utilisateurs-virtuels-dans-une-base-mysql</link>
		<comments>http://werk.feub.net/2008/08/postfix-dovecot-utilisateurs-virtuels-dans-une-base-mysql/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 11:07:29 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[mess]]></category>
		<category><![CDATA[messagerie]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=29</guid>
		<description><![CDATA[Amélioration du serveur de messagerie]]></description>
			<content:encoded><![CDATA[<p>
Dans <a href="http://feub.net/werk/index.php/feubv9/comments/serveur_de_messagerie_imap_simple_sous_fedora_9/" title="feub.net">cet article</a>, il a été vu comment mettre en place un serveur de messagerie simple grâce au <a href="http://fr.wikipedia.org/wiki/Mail_Transfer_Agent" title="Wikipedia">MTA</a> <a href="http://www.postfix.org/" title="Postfix">Postfix</a> et à <a href="http://www.dovecot.org/" title="Dovecot">Dovecot</a> pour l&#8217;<a href="http://fr.wikipedia.org/wiki/IMAP" title="Wikipedia">IMAP</a>. Cet article va ajouter la gestion des utilisateurs virtuels (des adresses emails) dans une base de données <a href="http://www-fr.mysql.com/" title="MySQL">MySQL</a>. Cet approche sera beaucoup plus souple dans la gestion du serveur, l&#8217;ajout/édition/suppression d&#8217;une adresse se fera très simplement en ajoutant un utilisateur dans la base des utilisateurs virtuels, alors qu&#8217;auparavant, il fallait ré-éditer des fichiers texte.
</p>
<p><span id="more-29"></span></p>
<p>
L&#8217;article suivant de <a href="http://www.llaumgui.com/" title="llaumgui.com">llaumgui</a> m&#8217;a bien aidé dans la mise en place du support MySQL : <a href="http://www.llaumgui.com/post/Serveur-mail-postfix-/-postfix-mysql-/-Dovecot-/-RoundCube-/-spamassassin-sous-CentOS-5" title="llaumgui.com">http://www.llaumgui.com/post/Serveur-mail-postfix-/-postfix-mysql-/-Dovecot-/-RoundCube-/-spamassassin-sous-CentOS-5</a>
</p>
<h4>Postfix</h4>
<p>
En premier lieu, la configuration du MTA doit être modifiée pour qu&#8217;il lise les domaines et utilisateurs virtuels dans la base MySQL et non plus dans un fichier de configuration. Il est supposé que le serveur MySQL est fonctionnel et qu&#8217;il existe une base accessible pour ajouter les tables.<br />
Voici le schéma de la table <em>MX_domains</em> des domaines virtuels à créer sur le serveur MySQL :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CREATE TABLE IF NOT EXISTS <span style="color: #000000; font-weight: bold;">`</span>MX_domains<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">`</span> tinyint<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">8</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL auto_increment,
<span style="color: #000000; font-weight: bold;">`</span>domain<span style="color: #000000; font-weight: bold;">`</span> varchar<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">128</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL,
PRIMARY KEY  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">ENGINE</span>=MyISAM  DEFAULT <span style="color: #007800;">CHARSET</span>=latin1 <span style="color: #007800;">AUTO_INCREMENT</span>=<span style="color: #000000;">2</span> ;</pre></div></div>

<p>
Et la table <em>MX_users</em> qui contiendra les informations des utilisateurs :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CREATE TABLE IF NOT EXISTS <span style="color: #000000; font-weight: bold;">`</span>MX_users<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">`</span> tinyint<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">8</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL auto_increment,
<span style="color: #000000; font-weight: bold;">`</span>email<span style="color: #000000; font-weight: bold;">`</span> varchar<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">128</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL,
<span style="color: #000000; font-weight: bold;">`</span>password<span style="color: #000000; font-weight: bold;">`</span> varchar<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">128</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL,
<span style="color: #000000; font-weight: bold;">`</span>name<span style="color: #000000; font-weight: bold;">`</span> varchar<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">128</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL default <span style="color: #ff0000;">''</span>,
<span style="color: #000000; font-weight: bold;">`</span>uid<span style="color: #000000; font-weight: bold;">`</span> smallint<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> unsigned NOT NULL default <span style="color: #ff0000;">'1000'</span>,
<span style="color: #000000; font-weight: bold;">`</span>gid<span style="color: #000000; font-weight: bold;">`</span> smallint<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> unsigned NOT NULL default <span style="color: #ff0000;">'1000'</span>,
<span style="color: #000000; font-weight: bold;">`</span>domain<span style="color: #000000; font-weight: bold;">`</span> varchar<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">128</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL default <span style="color: #ff0000;">''</span>,
<span style="color: #000000; font-weight: bold;">`</span>maildir<span style="color: #000000; font-weight: bold;">`</span> varchar<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">255</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL default <span style="color: #ff0000;">''</span>,
<span style="color: #000000; font-weight: bold;">`</span>is_imap<span style="color: #000000; font-weight: bold;">`</span> tinyint<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> unsigned NOT NULL default <span style="color: #ff0000;">'1'</span>,
<span style="color: #000000; font-weight: bold;">`</span>is_active<span style="color: #000000; font-weight: bold;">`</span> tinyint<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> NOT NULL default <span style="color: #ff0000;">'1'</span>,
PRIMARY KEY  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>,
UNIQUE KEY <span style="color: #000000; font-weight: bold;">`</span>address<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span>email<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>,
KEY <span style="color: #000000; font-weight: bold;">`</span>domain<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span>domain<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">ENGINE</span>=MyISAM  DEFAULT <span style="color: #007800;">CHARSET</span>=latin1 <span style="color: #007800;">AUTO_INCREMENT</span>=<span style="color: #000000;">4</span> ;</pre></div></div>

<p>
A noter que le champ <em>email</em> désigne la partie de l&#8217;adresse email avant l&#8217;arobase, par exemple pour toto@exemple.net, il faudra renseigner seulement <em>toto</em> dans le champ <em>email</em>. Le mot de passe quand à lui sera un hash <a href="http://fr.wikipedia.org/wiki/MD5" title="Wikipedia">MD5</a> dans la base.
</p>
<p>
Maintenant, il faut éditer le fichier <em>main.cf</em> de configuration de Postfix, en changeant ces deux lignes :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">virtual_mailbox_domains = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>domains
virtual_mailbox_maps = <span style="color: #7a0874; font-weight: bold;">hash</span>:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>user_mailboxes_path</pre></div></div>

<p>
Par :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">virtual_mailbox_domains = mysql:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>mysql_virtual_domains.cf
virtual_mailbox_maps = mysql:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>mysql_virtual_mailboxes.cf</pre></div></div>

<p>
Le préfixe <em>mysql</em> indique bien que les données vont être extraites de la base de données relationel. Mais les<br />
deux fichiers <em>mysql_virtual_domains.cf</em> et <em>mysql_virtual_mailboxes.cf</em> correspondant contenant les<br />
requêtes SQL ne sont pas encore crées. Les voici :
</p>
<p>mysql_virtual_domains.cf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user = dbuser
password = dbpassword
dbname = mailserver
hosts = localhost
query = SELECT <span style="color: #c20cb9; font-weight: bold;">id</span> FROM MX_domains WHERE <span style="color: #007800;">domain</span>=<span style="color: #ff0000;">'%s'</span></pre></div></div>

<p>mysql_virtual_mailboxes.cf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user = dbuser
password = dbpassword
dbname = mailserver
hosts = localhost
query = SELECT maildir FROM MX_users WHERE <span style="color: #007800;">email</span>=<span style="color: #ff0000;">'%s'</span> AND <span style="color: #007800;">is_active</span>=<span style="color: #000000;">1</span></pre></div></div>

<p>
Postfix peut être redémarré :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/init.d/postfix restart</span></pre></div></div>

<h4>Dovecot</h4>
<p>
La première chose à faire est d&#8217;ajouter le module MySQL pour Dovecot, sous <a href="http://www.fedora-fr.org/" title="Fedora">Fedora</a> :
</p>
<pre lang=bash">
# yum install dovecot-mysql
</pre>
<p>
En ce qui concerne sa configuration, les manipulations sont un peu similaires, à savoir, créer des fichiers de requêtes SQL pour<br />
que le serveur IMAP ramène les bonnes données de la base et non plus d&#8217;un fichier plat. Voici la partie qui va être<br />
modifiée du fichier <em>/etc/dovecot.conf</em> pour passer de :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mechanisms = plain
passdb passwd-file <span style="color: #7a0874; font-weight: bold;">&#123;</span>
args = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>users.conf
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>
A ceci :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mechanisms = plain <span style="color: #c20cb9; font-weight: bold;">login</span> digest-md5 cram-md5
passdb sql <span style="color: #7a0874; font-weight: bold;">&#123;</span>
args = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>mysql_users.cf
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>
On note l&#8217;ajout des mécanismes avec hash : digest-md5 (je n&#8217;avais mis que la gestion de mot de passe en texte brut dans l&#8217;article précédent). Ainsi que la vérification du mot de passe qui ne se fait plus par un fichier mais par une requête SQL dans le fichier <em>mysql_users.cf</em> sous /etc/postfix/dovecot/ (choix arbitraire), comme suit :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">driver = mysql
connect = <span style="color: #007800;">host</span>=localhost <span style="color: #007800;">dbname</span>=mailserver <span style="color: #007800;">user</span>=dbuser <span style="color: #007800;">password</span>=dbpassword
default_pass_scheme = PLAIN-MD5
password_query = SELECT password FROM MX_users \
WHERE email = <span style="color: #ff0000;">'%n'</span> AND is_active = <span style="color: #000000;">1</span>
user_query = SELECT concat<span style="color: #7a0874; font-weight: bold;">&#40;</span>email, <span style="color: #ff0000;">'@'</span>, domain<span style="color: #7a0874; font-weight: bold;">&#41;</span> AS user \
FROM MX_users WHERE email = <span style="color: #ff0000;">'%n'</span></pre></div></div>

<p>
Dovecot veut l&#8217;adresse complète comme nom d&#8217;utilisateur, donc on utilise la fonction concat() de MySQL pour la construire.<br />
A noter que la partie <em>userdb</em> pourrait être dans une table également, mais elle est laissée comme telle en <em>static</em>, car l&#8217;emplacement des messages ne bougera pas dans ce cas-ci, ils seront toujours sous <em>/home/vmail/domaine/utilisateur</em> et seront crées automatiquement lors d&#8217;ajout de nouvelles boîtes virtuelles :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">userdb static <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #666666; font-style: italic;"># Chemin vers les BAL</span>
args = <span style="color: #007800;">uid</span>=vmail <span style="color: #007800;">gid</span>=vmail <span style="color: #007800;">home</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vmail<span style="color: #000000; font-weight: bold;">/%</span>d<span style="color: #000000; font-weight: bold;">/%</span>n<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>
Redémarrage de Dovecot :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/init.d/dovecot restart</span></pre></div></div>

<p>
Tout devrait fonctionner maintenant. Pour ajouter/supprimer/éditer un utilisateur, il suffit de le faire dans la base de données, par exemple par l&#8217;intermédiaire de <a href="http://www.phpmyadmin.net/" title="phpMyAdmin">phpMyAdmin</a> ou d&#8217;un script <a href="http://fr.wikipedia.org/wiki/Bourne-Again_shell" title="Wikipedia">bash</a> (ou autre langage) qui fera peut-être l&#8217;objet d&#8217;un prochain article.
</p>
<p>
Note : les anti-slash \ ne sont pas à taper, ils indiquent que j&#8217;ai coupé les lignes pour que ça ne dépasse pas du cadre. Il s&#8217;agit d&#8217;une seule et même ligne.
</p>
<div class="related-links">
<h4>
Article en relation : <strong>Serveur de messagerie</strong> :<br />
</h4>
<ul>
<li><a href="http://feub.net/werk/index.php/feubv9/comments/serveur_de_messagerie_imap_simple_sous_fedora_9/" title="feub.net">Serveur de messagerie IMAP simple sous Fedora_9</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2008/08/postfix-dovecot-utilisateurs-virtuels-dans-une-base-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc (Feed is rejected)
Page Caching using apc
Object Caching 460/553 objects using memcached

Served from: werk.feub.net @ 2012-02-09 00:33:36 -->
