<?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>Johnny Chadda .se &#187; mail</title>
	<atom:link href="http://johnny.chadda.se/tag/mail/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnny.chadda.se</link>
	<description>Things you didn&#039;t know that you should know</description>
	<lastBuildDate>Wed, 28 Jul 2010 14:13:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Updating the Postfix HOWTO</title>
		<link>http://johnny.chadda.se/article/updating-the-postfix-howto/</link>
		<comments>http://johnny.chadda.se/article/updating-the-postfix-howto/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 21:45:03 +0000</pubDate>
		<dc:creator>Johnny Chadda</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://johnny.chadda.se/?p=412</guid>
		<description><![CDATA[The time has come to]]></description>
			<content:encoded><![CDATA[<p>The time has come to update the <a title="Postfix HOWTO" href="http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/">Postfix HOWTO</a> for Debian and Ubuntu on the website. There are lots of changes done in the <a title="Postfix" href="http://www.postfix.org/" onclick="pageTracker._trackPageview('/outgoing/www.postfix.org/?referer=');">Postfix</a> and <a title="Dovecot" href="http://www.dovecot.org/" onclick="pageTracker._trackPageview('/outgoing/www.dovecot.org/?referer=');">Dovecot</a> distribution, as well as input from lots of <a title="commenters" href="http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/#comments">commenters</a>. The release of the latest <a title="Debian" href="http://www.debian.org/" onclick="pageTracker._trackPageview('/outgoing/www.debian.org/?referer=');">Debian</a> distribution called Etch, there have been some major improvements of various components.</p>
<p>Within the next couple of weeks, I will publish an updated version with hopefully additional features such as <a title="DSPAM" href="http://dspam.nuclearelephant.com/" onclick="pageTracker._trackPageview('/outgoing/dspam.nuclearelephant.com/?referer=');">DSPAM</a> and other important components for creating an enterprise grade mail server.</p>
<p>I have realized that it is impossible to manage such a large document as a normal post, so if there is time, I will create it using Latex or some other tool to manage large documents.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnny.chadda.se/article/updating-the-postfix-howto/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mail server HOWTO &#8211; Postfix and Dovecot with MySQL and TLS/SSL, Postgrey and DSPAM</title>
		<link>http://johnny.chadda.se/article/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/</link>
		<comments>http://johnny.chadda.se/article/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/#comments</comments>
		<pubDate>Sun, 15 Apr 2007 12:47:20 +0000</pubDate>
		<dc:creator>Johnny Chadda</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/</guid>
		<description><![CDATA[This guide describes how to]]></description>
			<content:encoded><![CDATA[<p>This guide describes how to setup a mail server where Postfix is the SMTP service, and Dovecot provides IMAP and POP services. The users may be virtual and stored in a MySQL table, or real system users, or both. The primary focus for this guide however, is a fast and secure mail server using virtual users.</p>
<p><span id="more-266"></span></p>
<p>All this may be installed in either Debian 4.0 Etch or Ubuntu Feisty Fawn, since both systems are quite similar. Note however that there may be some minor issues if you use the default version of Dovecot, but I will try to note them down for you when they arise.</p>
<p class="information">If you are a Ubuntu user, note that I will not use &#8220;sudo&#8221; in front of every command. Instead, I will launch a root shell using the command &#8220;sudo -s&#8221;.</p>
<p class="information">Note that ticks like &#8216; and &#8221; are converted by WordPress, and may cause problems if copied directly into your configuration.</p>
<h2>MySQL and Postfix admin</h2>
<p>Installing software in Ubuntu and Debian is very easy, and to get the MySQL server and client installed, just execute the following.</p>
<blockquote>
<p class="code"># apt-get install mysql-server mysql-client</p>
</blockquote>
<p>Step one is to set a password for the administrative user, which can be done with the following statement. See the <a onclick="pageTracker._trackPageview('/outgoing/dev.mysql.com/doc/refman/5.0/en/default-privileges.html?referer=');pageTracker._trackPageview('/outgoing/dev.mysql.com/doc/refman/5.0/en/default-privileges.html?referer=http://johnny.chadda.se/?s=postfix&amp;searchsubmit=Find');pageTracker._trackPageview('/outgoing/dev.mysql.com/doc/refman/5.0/en/default-privileges.html?referer=http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/');" href="http://dev.mysql.com/doc/refman/5.0/en/default-privileges.html">MySQL documentation</a> for more information.</p>
<blockquote>
<p class="code"># mysqladmin -u root password &#8220;newpwd&#8221;</p>
</blockquote>
<p>Of couse, replace newpwd with your intended password. While you are at it, add a user mail with password mail, with access to database mail. You can of course change the password to something else if you wish, and you may give more restrictive permissions if you know what you are doing. Postfix and Dovecot will only SELECT from the database, while postfix admin will SELECT, UPDATE and INSERT into the database. You may even create two separate accounts for this. This guide however will use the same account.</p>
<blockquote>
<p class="code">#  mysql -uroot -p<br />
mysql&gt; CREATE DATABASE mail;<br />
mysql&gt; GRANT ALL PRIVILEGES ON mail.* TO &#8216;mail&#8217;@'localhost&#8217; IDENTIFIED BY &#8216;mail&#8217;;<br />
mysql&gt; quit</p>
</blockquote>
<p>Now we need to download <a onclick="pageTracker._trackPageview('/outgoing/sourceforge.net/projects/postfixadmin/?referer=');pageTracker._trackPageview('/outgoing/sourceforge.net/projects/postfixadmin/?referer=http://johnny.chadda.se/?s=postfix&amp;searchsubmit=Find');pageTracker._trackPageview('/outgoing/sourceforge.net/projects/postfixadmin/?referer=http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/');" href="http://sourceforge.net/projects/postfixadmin/">Postfix admin</a>, since its distribution contains the required SQL schema which we want to use.</p>
<p>Once you have downloaded the Postfix admin distribution, you should have a tarball, and unpack it like this.</p>
<blockquote>
<p class="code"># tar xvfz postfixadmin-2.1.0.tgz</p>
</blockquote>
<p>Open &#8220;postfixadmin-2.1.0/DATABASE_MYSQL.TXT&#8221; with your favorite editor such as vim, nano or gedit and comment out or remove all lines under section &#8220;Postfix / MySQL&#8221;, since we have created our own use for the mail server. The section is currently lines 26 to 39.</p>
<p>When this is done, just load the file into mysql using the following command.</p>
<blockquote>
<p class="code"># mysql -umail -p mail &lt; postfixadmin-2.1.0/DATABASE_MYSQL.TXT</p>
</blockquote>
<p>If you get an error saying &#8220;Access denied for user &#8216;mail&#8217;@'localhost&#8217; to database &#8216;mysql&#8217;&#8221;, you didn&#8217;t comment out the lines like I told you. If you get no message after entering your password, everything went fine.</p>
<h2>Postfix</h2>
<p>Since we are using a Debian based system, installing Postfix is a walk in the park.</p>
<blockquote>
<p class="code">apt-get install postfix postfix-mysql</p>
</blockquote>
<p>If you get questions about Postfix during the installation, just select &#8220;No configuration&#8221;. You have this guide, which will configure it for you instead!</p>
<p>The Postfix configuration directory is located in /etc/postfix, so head over there and open the file main.cf. Don&#8217;t worry if it does not exist. We will make it!</p>
<p>Start with entering the following basic information.</p>
<blockquote>
<p class="code">smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)<br />
biff = no<br />
append_dot_mydomain = no<br />
#delay_warning_time = 4h<br />
myhostname = mail.mycompany.com<br />
myorigin = mycompany.com<br />
mydestination = localhost<br />
relayhost =<br />
mynetworks = 127.0.0.0/8<br />
mailbox_size_limit = 0<br />
recipient_delimiter = +<br />
inet_interfaces = all</p>
</blockquote>
<p>This is actually all you need to get a fully functional mail server with standard unix users. Remember however to change myhostname and myorigin to your own domain settings.</p>
<h3>Virtual users</h3>
<p>Now for adding support for virtual users in MySQL, also append the following lines to the main.cf configuration file.</p>
<blockquote>
<p class="code"># Virtual mailbox settings<br />
virtual_mailbox_domains = proxy:mysql:$config_directory/mysql_virtual_domains_maps.cf<br />
virtual_mailbox_base = /var/vmail<br />
virtual_mailbox_maps = proxy:mysql:$config_directory/mysql_virtual_mailbox_maps.cf<br />
virtual_alias_maps = proxy:mysql:$config_directory/mysql_virtual_alias_maps.cf<br />
virtual_minimum_uid = 150<br />
virtual_uid_maps = static:150<br />
virtual_gid_maps = static:8<br />
virtual_transport = dovecot<br />
dovecot_destination_recipient_limit = 1<br />
# SASL Authentication<br />
smtpd_sasl_auth_enable          = yes<br />
smtpd_sasl_exceptions_networks  = $mynetworks<br />
smtpd_sasl_security_options     = noanonymous<br />
broken_sasl_auth_clients        = yes<br />
smtpd_sasl_type                 = dovecot<br />
smtpd_sasl_path                 = private/auth</p>
</blockquote>
<p>There are several gotchas here. This configuration will host the virtual user mailboxes in /var/vmail. Should these mailboxes be hosted somewhere else, be sure to change that as appropriate.</p>
<p>The &#8220;virtual_minimum_uid&#8221; and &#8220;virtual_uid_maps&#8221; point to user id 150 in my case, which is a user I created specifically for handling virtual mail. It uses the standard &#8220;mail&#8221; group with the default gid 8 (in Debian and Ubuntu). Create the user and directories like this:</p>
<blockquote>
<p class="code">#  useradd -r -u 150 -g mail -d /var/vmail -s /sbin/nologin -c &#8220;Virtual mailbox&#8221; vmail<br />
# mkdir /var/vmail<br />
# chmod 770 /var/vmail/<br />
# chown vmail:mail /var/vmail/</p>
</blockquote>
<h3>Select which clients to permit</h3>
<p>We also need to specify some rules, which will enable authenticated users to send mail, but not anyone.</p>
<p class="alert">Being an open relay is absolutely forbidden!</p>
<blockquote>
<p class="code">smtpd_recipient_restrictions =<br />
permit_mynetworks<br />
permit_sasl_authenticated<br />
reject_unauth_destination<br />
permit</p>
</blockquote>
<p class="information">For antispam measures and enabling TLS, see further down in this document.</p>
<h3>Postfix MySQL configuration</h3>
<p>Postfix needs to know where and how it can lookup all mailbox related information, so it needs to be provided with all MySQL files defined in the main.cf configuration. Note that the last line contains a comment line with the full query. Recent versions of Postfix may use that instead of the other statements, and in that case, just comment all lines out, and uncomment the last one.</p>
<p>/etc/postfix/mysql_virtual_alias_maps.cf</p>
<blockquote>
<p class="code">user            = mail<br />
password        = mail<br />
hosts           = localhost<br />
dbname          = mail<br />
table           = alias<br />
select_field    = goto<br />
where_field     = address<br />
additional_conditions = and active = &#8217;1&#8242;<br />
#query           = SELECT goto FROM alias WHERE address=&#8217;%s&#8217; AND active = &#8217;1&#8242;</p>
</blockquote>
<p>/etc/postfix/mysql_virtual_domains_maps.cf</p>
<blockquote>
<p class="code">user            = mail<br />
password        = mail<br />
hosts           = localhost<br />
dbname          = mail<br />
table           = domain<br />
select_field    = domain<br />
where_field     = domain<br />
additional_conditions = and backupmx = &#8217;0&#8242; and active = &#8217;1&#8242;<br />
#query           = SELECT domain FROM domain WHERE domain=&#8217;%s&#8217; AND backupmx = &#8217;0&#8242; AND active = &#8217;1&#8242;</p>
</blockquote>
<p>/etc/postfix/mysql_virtual_mailbox_limit_maps.cf</p>
<blockquote>
<p class="code">user            = mail<br />
password        = mail<br />
hosts           = localhost<br />
dbname          = mail<br />
table           = mailbox<br />
select_field    = quota<br />
where_field     = username<br />
additional_conditions = and active = &#8217;1&#8242;<br />
#query           = SELECT quota FROM mailbox WHERE username=&#8217;%s&#8217; AND active = &#8217;1&#8242;</p>
</blockquote>
<p>/etc/postfix/mysql_virtual_mailbox_maps.cf</p>
<blockquote>
<p class="code">user            = mail<br />
password        = mail<br />
hosts           = localhost<br />
dbname          = mail<br />
table           = mailbox<br />
select_field    = CONCAT(domain,&#8217;/',maildir)<br />
where_field     = username<br />
additional_conditions = and active = &#8217;1&#8242;<br />
#query           = SELECT CONCAT(domain,&#8217;/',maildir) FROM mailbox WHERE username=&#8217;%s&#8217; AND active = &#8217;1&#8242;</p>
</blockquote>
<h3>Dovecot delivery for Postfix</h3>
<p>Postfix will hand the mail over to Dovecot for local delivery, and to set this up, you need to open the file /etc/postfix/master.cf and add the following like at the bottom.</p>
<blockquote>
<p class="code">dovecot   unix  &#8211;       n       n       &#8211;       &#8211;       pipe    flags=DRhu user=<br />
vmail:mail argv=/usr/lib/dovecot/deliver -d $(recipient)</p>
</blockquote>
<h2>Dovecot IMAP and POP</h2>
<p>The first step is to get the packages installed, and it&#8217;s simply a matter of using apt-get like before.</p>
<blockquote>
<p class="code">apt-get install dovecot-imapd dovecot-pop3d</p>
</blockquote>
<p>You can of course omit the &#8220;dovecot-pop3d&#8221; package, if you are not planning on using POP, and why should you, when IMAP provides such wonderful extensions such as IDLE?</p>
<p>Open up the Dovecot configuration file located in /etc/dovecot/dovecot.conf and make it look the following. There is probably already lots of default configuration done, so you will probably only need to uncomment certain sections and change minor things.</p>
<blockquote>
<p class="code">## Dovecot configuration file<br />
#<br />
base_dir = /var/run/dovecot/<br />
#<br />
# imap imaps pop3 pop3s (use imaps and pop3s if configured for SSL)<br />
protocols = imap pop3<br />
#<br />
# Uncomment the ssl_listen statements and comment out listen if using SSL<br />
protocol imap {<br />
listen = *:143<br />
#    ssl_listen = *:993<br />
}<br />
protocol pop3 {<br />
listen = *:110<br />
#     ssl_listen = *:995<br />
}<br />
#<br />
log_timestamp = &#8220;%Y-%m-%d %H:%M:%S &#8221;<br />
syslog_facility = mail<br />
#<br />
# Uncomment these if using SSL<br />
#ssl_cert_file = /etc/ssl/mycompany/mailserver/mail-cert.pem<br />
#ssl_key_file = /etc/ssl/mycompany/mailserver/mail-key.pem<br />
#ssl_ca_file = /etc/ssl/mycompany/ca/mycompany.pem<br />
#ssl_verify_client_cert = yes<br />
#ssl_parameters_regenerate = 168<br />
#verbose_ssl = no<br />
#<br />
# Where the mailboxes are located<br />
mail_location = maildir:/var/vmail/%d/%u<br />
#<br />
mail_extra_groups = mail<br />
mail_debug = no<br />
first_valid_uid = 150<br />
last_valid_uid = 150<br />
maildir_copy_with_hardlinks = yes<br />
#<br />
protocol imap {<br />
login_executable = /usr/lib/dovecot/imap-login<br />
mail_executable = /usr/lib/dovecot/imap<br />
imap_max_line_length = 65536<br />
}<br />
protocol pop3 {<br />
login_executable = /usr/lib/dovecot/pop3-login<br />
mail_executable = /usr/lib/dovecot/pop3<br />
pop3_uidl_format = %08Xu%08Xv<br />
}<br />
protocol lda {<br />
postmaster_address = postmaster@mydomain.com<br />
sendmail_path = /usr/lib/sendmail<br />
auth_socket_path = /var/run/dovecot/auth-master<br />
}<br />
#<br />
auth_verbose = no<br />
auth_debug = no<br />
auth_debug_passwords = no<br />
#<br />
auth default {<br />
mechanisms = plain<br />
passdb sql {<br />
args = /etc/dovecot/dovecot-sql.conf<br />
}<br />
userdb sql {<br />
args = /etc/dovecot/dovecot-sql.conf<br />
}<br />
user = nobody<br />
socket listen {<br />
master {<br />
path = /var/run/dovecot/auth-master<br />
mode = 0660<br />
user = vmail<br />
group = mail<br />
}<br />
client {<br />
path = /var/spool/postfix/private/auth<br />
mode = 0660<br />
user = postfix<br />
group = postfix<br />
}<br />
}<br />
#<br />
# If you want client certificates, use these lines<br />
#  ssl_require_client_cert = yes<br />
#  ssl_username_from_cert = yes<br />
}</p>
</blockquote>
<p>Yes, the indentation was lost, but don&#8217;t fear. Just incorporate my changes to the existing file. The Dovecot configuration is almost finished now, but we need to add definitions on how it can find our password and user database stored in MySQL.</p>
<p>Open the file /etc/dovecot/dovecot-sql.conf and make sure that the following is present.</p>
<blockquote>
<p class="code">driver = mysql<br />
connect = host=localhost dbname=mail user=mail password=mail<br />
# The new name for MD5 is MD5-CRYPT so you might need to change this depending on version<br />
default_pass_scheme = MD5<br />
# Get the mailbox<br />
user_query = SELECT &#8216;/var/vmail/%d/%n&#8217; as home, &#8216;maildir:/var/vmail/%d/%n&#8217; as mail, 150 AS uid, 8 AS gid, concat(&#8216;dirsize:storage=&#8217;, quota) AS quota FROM mailbox WHERE username = &#8216;%u&#8217; AND active = &#8217;1&#8242;<br />
# Get the password<br />
password_query = SELECT username as user, password, &#8216;/var/vmail/%d/%n&#8217; as userdb_home, &#8216;maildir:/var/vmail/%d/%n&#8217; as userdb_mail, 150 as userdb_uid, 8 as userdb_gid FROM mailbox WHERE username = &#8216;%u&#8217; AND active = &#8217;1&#8242;<br />
# If using client certificates for authentication, comment the above and uncomment the following<br />
#password_query = SELECT null AS password, &#8216;%u&#8217; AS user</p>
</blockquote>
<p>Set the permissions for Dovecot.</p>
<blockquote>
<p class="code"># chmod 600 /etc/dovecot/*.conf<br />
# chown vmail /etc/dovecot/*.conf</p>
</blockquote>
<p>The Dovecot configuration is now finished, but all SSL-specific parameters have been disabled for now.</p>
<h2>Postfix admin</h2>
<p>Since Postfix admin requires a running web server, Apache and PHP needs to be installed first. As always, apt-get comes to the rescure, and we need to restart Apache after the installation of php5-mysql.</p>
<blockquote>
<p class="code"># apt-get install apache2 libapache2-mod-php5 php5-mysql<br />
# invoke-rc.d apache2 restart</p>
</blockquote>
<p>To make things easy, just move the postfixadmin directory downloaded earlier to /var/www/ and copy the config file to its real name.</p>
<blockquote>
<p class="code"># mv postfixadmin-2.1.0 /var/www/postfixadmin<br />
# cd /var/www/postfixadmin/<br />
# cp config.inc.php.sample config.inc.php</p>
</blockquote>
<p>There are some directives you will need to change, and they are quite self-explanatory, but here are the highlights.</p>
<blockquote>
<p class="code">$CONF['postfix_admin_url'] = &#8216;/var/www/postfixadmin/&#8217;;<br />
$CONF['postfix_admin_path'] = &#8216;http://localhost/postfixadmin&#8217;;<br />
$CONF['database_type'] = &#8216;mysqli&#8217;;<br />
$CONF['database_user'] = &#8216;mail&#8217;;<br />
$CONF['database_password'] = &#8216;mail&#8217;;<br />
$CONF['database_name'] = &#8216;mail&#8217;;</p>
</blockquote>
<h2>Do some tests to see if everything works</h2>
<p>The server should now be fully up and running, so go to http://localhost/postfixadmin/admin/ and create a new domain and user. If you then look at the log file /var/log/syslog, you should see something like this.</p>
<blockquote>
<p class="code">postfix/smtpd[1819]: connect from localhost[127.0.0.1]<br />
postfix/smtpd[1819]: 1A0DF66886: client=localhost[127.0.0.1]<br />
postfix/cleanup[1824]: 1A0DF66886: message-id=&lt;20070415093021.1A0DF66886@mail.mydomain.com&gt;<br />
postfix/qmgr[1067]: 1A0DF66886: from= , size=408, nrcpt=1 (queue active)<br />
postfix/smtpd[1819]: disconnect from localhost[127.0.0.1]<br />
deliver(joch@mydomain.com): msgid=&lt;20070415093021.1A0DF66886@mail.mydomain.com&gt;: saved mail to INBOX<br />
postfix/pipe[1825]: 1A0DF66886: to=, relay=dovecot, delay=0.09, delays=0.06/0.01/0/0.02, dsn=2.0.0, status=sent (delivered via dovecot service)<br />
postfix/qmgr[1067]: 1A0DF66886: removed</p>
</blockquote>
<p>If you received an error, extract the error message and go from there.</p>
<h2>TLS and SSL for Postfix and Dovecot</h2>
<p>Before you push this server out into production, you will most definitely want to enable encryption. You can have different levels of security, and here are the most common scenarios.</p>
<p>The simplest form is having a simple self-signed certificate on the server. This will generate a warning message when the clients first connect, but they should be able to save it for further use. It is not really secure, since anyone can execute a man-in-the-middle attack if you don&#8217;t save the certificate.</p>
<p>The next level is using a server certificate signed by a Certificate Authority (CA), either a commercial one, or perhaps the company internal CA. This way, the server certificate will be trusted, and if you now receive a warning, there is potentially something bad going on.</p>
<p>Last but definitely not least is using client certificates for logging in to the server, and using a server certificate to authenticate the server to the clients. This is quite secure, but it is not supported in all mail clients. Thunderbird among others do have support for it.</p>
<h3>Self-signed server certificate</h3>
<p>First create the directories, create the private key, and lastly create the certificate.</p>
<blockquote>
<p class="code"># mkdir -p /etc/ssl/mycompany/mailserver/<br />
# cd /etc/ssl/mycompany/mailserver/<br />
# openssl genrsa 1024 &gt; mail-key.pem<br />
# chmod 400 mail-key.pem<br />
# openssl req -new -x509 -nodes -sha1 -days 365 -key mail-key.pem &gt; mail-cert.pem</p>
</blockquote>
<p class="information">Note that &#8220;Common Name (eg, YOUR name)&#8221; MUST match the name of the server, which in this case is mail.mycompany.com</p>
<h3>Dovecot SSL configuration</h3>
<p>When you have the certificate ready, it needs to be enabled in both Dovecot and Postfix. You will need to uncomment the following directives in dovecot.conf</p>
<blockquote>
<p class="code">protocols<br />
ssl_listen<br />
ssl_cert_file<br />
ssl_key_file<br />
ssl_parameters_regenerate = 168<br />
verbose_ssl = no</p>
</blockquote>
<p>Dovecot should now be accepting SSL-connections on port 993. Check the log-file for an entry like this when you login using IMAP.</p>
<blockquote>
<p class="code">dovecot: imap-login: Login: user=, method=PLAIN, rip=127.0.1.1, lip=127.0.1.1, TLS</p>
</blockquote>
<p>The keyword is TLS to the right, which shows that you are using a TLS encrypted session.</p>
<h3>Postfix TLS configuration</h3>
<p>You will need to add a few lines to your main.cf configuration file to enable TLS.</p>
<blockquote>
<p class="code">smtpd_tls_cert_file = /etc/ssl/mycompany/mailserver/mail-cert.pem<br />
smtpd_tls_key_file = /etc/ssl/mycompany/mailserver/mail-key.pem<br />
smtpd_tls_session_cache_database = btree:/var/spool/postfix/smtpd_tls_session_cache<br />
smtpd_tls_security_level = may<br />
smtpd_tls_received_header = no<br />
smtpd_tls_loglevel = 0<br />
tls_random_source = dev:/dev/urandom</p>
</blockquote>
<p>Now you should be able to authenticate with Postfix and send mail anywhere.</p>
<h3>CA-signed certificate</h3>
<p>Using a real CA-signed certificate is no different from using a self-signed one. It&#8217;s just another step in the key-pair creation. If your company has its own CA, then they should issue a certificate for the mail server. A Google search for <a onclick="pageTracker._trackPageview('/outgoing/www.google.se/search?q=be+your+own+ca&amp;referer=');pageTracker._trackPageview('/outgoing/www.google.se/search?q=be+your+own+ca&amp;referer=http://johnny.chadda.se/?s=postfix&amp;searchsubmit=Find');pageTracker._trackPageview('/outgoing/www.google.se/search?q=be+your+own+ca&amp;referer=http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/');" href="http://www.google.se/search?q=be+your+own+ca">be your own ca</a> will give you enough answers to create one yourself, if you have the need.</p>
<h3>CA-signed client and server certificates</h3>
<p>If you want to use CA-signed client certificates, you will need to take further steps, both in Postfix and in Dovecot to make this work. If you want the user names to be taken from the certificate itself, you currently must set the common name to the user name, for example joch@mycompany.com, which has been used in this document.</p>
<p>In Postfix, you can either use a directory of CA certificates, or a composite file with all the certificates concatenated together.</p>
<blockquote>
<p class="code">smtpd_tls_CAfile = /etc/ssl/mycompany/ca/all.pem<br />
#smtpd_tls_CApath = /etc/ssl/mycompany/ca/</p>
</blockquote>
<p>In Dovecot, you must have the CRL together with the certificate for the authentication to work. The directives themselves are the following.</p>
<blockquote>
<p class="code">ssl_ca_file = /etc/ssl/mycompany/ca/all.pem<br />
ssl_verify_client_cert = yes<br />
ssl_require_client_cert = yes<br />
ssl_username_from_cert = yes</p>
</blockquote>
<p>You will also need to change the password_query to the commented one in /etc/dovecot/dovecot-sql.conf</p>
<p class="alert">If you are running Dovecot release candidate 28 or older, the server will not send out the list of accepted CA names, which could make clients with multiple client certificates unable to connect. Please upgrade or install <a href="http://johnny.chadda.se/2007/04/03/get-client-certificates-working-correctly-in-dovecot/">this patch</a>.</p>
<p>If you have several CAs and CRLs, it could be difficult to concatenate them each time, so I have created a small script which will do that for you. Just stick it in your /etc/ssl/mycompany/ca/ directory and run it. It will create an all.pem with all certificates and all CRLs.</p>
<blockquote>
<p class="code">make.sh:<br />
#!/bin/bash<br />
rm all.pem 2&gt; /dev/null<br />
cat *.pem *.crl &gt; all.pem</p>
</blockquote>
<p>Like I said before, there are some settings in Postfix that need to be changed as well, so open up main.cf and note the following.</p>
<blockquote>
<p class="code">smtp_tls_CAfile = /etc/ssl/mycompany/ca/all.pem<br />
smtpd_tls_ask_ccert = yes<br />
smtpd_tls_req_ccert = no<br />
smtpd_recipient_restrictions =<br />
permit_mynetworks<br />
permit_tls_all_clientcerts<br />
reject_unauth_destination<br />
permit</p>
</blockquote>
<p>Now you should have an enterprise ready email server with client certificates.</p>
<h2>Anti-spam measures</h2>
<p>Everyone hates spam, so you will need to take some measures to protect your users from it.</p>
<h3>Postgrey</h3>
<p><a onclick="pageTracker._trackPageview('/outgoing/www.greylisting.org/?referer=');pageTracker._trackPageview('/outgoing/www.greylisting.org/?referer=http://johnny.chadda.se/?s=postfix&amp;searchsubmit=Find');pageTracker._trackPageview('/outgoing/www.greylisting.org/?referer=http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/');" href="http://www.greylisting.org/">Greylisting</a> is a fairly effective countermeasure against spam, so we of course want to enable it for Postfix. First of all, let&#8217;s get <a onclick="pageTracker._trackPageview('/outgoing/postgrey.schweikert.ch/?referer=');pageTracker._trackPageview('/outgoing/postgrey.schweikert.ch/?referer=http://johnny.chadda.se/?s=postfix&amp;searchsubmit=Find');pageTracker._trackPageview('/outgoing/postgrey.schweikert.ch/?referer=http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/');" href="http://postgrey.schweikert.ch/">Postgrey</a> installed and as always, that is very easy in Debian and Ubuntu.</p>
<p class="information">You can use other greylisting daemons which use MySQL for example if you like, but then you are on your own.</p>
<blockquote>
<p class="code"># apt-get install postgrey</p>
</blockquote>
<p>Postgrey will be injected before Postfix handles over the delivery to Dovecot, so we need to add it in the very end of &#8220;smtpd_recipient_restrictions&#8221; in main.cf, just before the final &#8220;permit&#8221; rule.</p>
<blockquote>
<p class="code">check_policy_service inet:127.0.0.1:60000</p>
</blockquote>
<p>Open up /etc/default/postgrey in your favourit editor and change the options line to the following. Yes, there should be two dashes, &#8211; -, but WordPress makes them to one long.</p>
<blockquote>
<p class="code">POSTGREY_OPTS=&#8221;&#8211;inet=127.0.0.1:60000 &#8211;delay=55&#8243;</p>
</blockquote>
<p>Then restart postgrey and incoming mail will be delayed 55 seconds, and you will hopefully get a lot less spam!</p>
<blockquote>
<p class="code"># invoke-rc.d postgrey restart</p>
</blockquote>
<h3>Postfix RBL and other rules</h3>
<p>There are other rules you can add to Postfix which will reduce spam. Incorporate the following into your main.cf configuration.</p>
<blockquote>
<p class="code">smtpd_recipient_restrictions =<br />
permit_mynetworks<br />
permit_tls_all_clientcerts<br />
#permit_sasl_authenticated<br />
reject_non_fqdn_hostname<br />
reject_non_fqdn_sender<br />
reject_non_fqdn_recipient<br />
reject_unauth_destination<br />
reject_unauth_pipelining<br />
reject_invalid_hostname<br />
#reject_unknown_sender_domain<br />
#reject_unknown_hostname<br />
reject_rbl_client zen.spamhaus.org<br />
reject_rbl_client bl.spamcop.net<br />
reject_rbl_client cbl.abuseat.org<br />
reject_rbl_client dnsbl.njabl.org<br />
reject_rbl_client dnsbl.sorbs.net<br />
reject_rhsbl_sender dsn.rfc-ignorant.org<br />
check_policy_service inet:127.0.0.1:60000<br />
permit<br />
#<br />
smtpd_data_restrictions =<br />
reject_unauth_pipelining,<br />
reject_multi_recipient_bounce,<br />
permit</p>
<p>Note that I have commented out &#8220;reject_unknown_hostname&#8221;, because there are some legit mail servers out there that send the wrong host name. That rule does however catch lots of spam, so it&#8217;s a call you will have to make.</p></blockquote>
<p>You now have a reasonable protection against spam. There are other server-side filtering services which use the bayesian algorithm to catch most spam.</p>
<h3>DSPAM</h3>
<p>Sorry, to be added later.</p>
<h2>Final remarks</h2>
<p>This guide will aid you in setting up a large-scale mail server, but it is always important to understand that you should take care and explore all options before diving in and setting this up in a real environment. There are probably lots of things that can be improved in this setup, but I will leave that up to you.</p>
<p>This setup will scale rather well, as you can cleanly separate the different component onto separate machines to reduce the load.</p>
<p>To conclude, always pay close attention to the logs. I always tail syslog when doing these kinds of things and you should too.</p>
<blockquote>
<p class="code"># tail -f /var/log/syslog</p>
</blockquote>
<p>The above command will give you a real-time log when things happen, so keep one terminal running with just this.</p>
<h2>References and further reading</h2>
<ul>
<li><a onclick="pageTracker._trackPageview('/outgoing/wiki.dovecot.org/DovecotLDAPostfixAdminMySQL?referer=');pageTracker._trackPageview('/outgoing/wiki.dovecot.org/DovecotLDAPostfixAdminMySQL?referer=http://johnny.chadda.se/?s=postfix&amp;searchsubmit=Find');pageTracker._trackPageview('/outgoing/wiki.dovecot.org/DovecotLDAPostfixAdminMySQL?referer=http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/');" href="http://wiki.dovecot.org/DovecotLDAPostfixAdminMySQL">DovecotLDAPostfixAdminMySQL</a></li>
<li><a onclick="pageTracker._trackPageview('/outgoing/postfix.wiki.xs4all.nl/index.php?title=Virtual_Users_and_Domains_with_Courier-IMAP_and_MySQL/&amp;referer=');pageTracker._trackPageview('/outgoing/postfix.wiki.xs4all.nl/index.php?title=Virtual_Users_and_Domains_with_Courier-IMAP_and_MySQL/&amp;referer=http://johnny.chadda.se/?s=postfix&amp;searchsubmit=Find');pageTracker._trackPageview('/outgoing/postfix.wiki.xs4all.nl/index.php?title=Virtual_Users_and_Domains_with_Courier-IMAP_and_MySQL/&amp;referer=http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/');" href="http://postfix.wiki.xs4all.nl/index.php?title=Virtual_Users_and_Domains_with_Courier-IMAP_and_MySQL/">Virtual Users and Domains with Courier-IMAP and MySQL</a></li>
</ul>
<p>If you find this howto useful, please consider making a small (or large) <a title="donate" href="http://johnny.chadda.se/donate/">donation</a> to contribute to enhancements and new guides.</p>
<ul></ul>
]]></content:encoded>
			<wfw:commentRss>http://johnny.chadda.se/article/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/feed/</wfw:commentRss>
		<slash:comments>210</slash:comments>
		</item>
		<item>
		<title>Postfix HOWTO</title>
		<link>http://johnny.chadda.se/article/postfix-howto/</link>
		<comments>http://johnny.chadda.se/article/postfix-howto/#comments</comments>
		<pubDate>Sat, 30 Apr 2005 08:57:23 +0000</pubDate>
		<dc:creator>Johnny Chadda</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://johnny.chadda.se/2005/04/30/postfix-howto/</guid>
		<description><![CDATA[This guide will help you]]></description>
			<content:encoded><![CDATA[<p>This guide will help you install a complete mail server for the home, office and even an ISP. The guide follows a freshly installed Debian Sarge (currently testing) system, and uses Postfix, Courier IMAP, SASL, MySQL, Postfix admin, Squirrelmail and other nice software packages.</p>
<p class="information">This HOWTO has probably been slightly outdated lately, since I have not had time to update it.</p>
<p class="new">New HOWTO available: <a href="http://johnny.chadda.se/2007/04/15/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/">Mail server HOWTO &#8211; Postfix and Dovecot with MySQL and TLS/SSL, Postgrey and DSPAM</a></p>
<h2>Prerequisites</h2>
<p>Before getting started with the Postfix installation, the mysql server should be installed. We also need the mysql-client to populate the tables in the Postfix database:</p>
<blockquote>
<p class="code"># apt-get install mysql-server mysql-client</p>
</blockquote>
<p>Note that the default MySQL installation in Debian does not have a password for the root user. Before continuing with this guide, set a root password! This is a far too easy thing to forget later on and it can have tremendous security implications.</p>
<p>Now it is time to download the Postfix admin software. It is a virtual user administraton system written in PHP for the Postfix SMTP server. Head over to a temporary directory and download the archive from their site. When wget is done, unpack the file and enter the directory. Now we want to populate our MySQL database with the schema provided by Postfix admin:</p>
<blockquote>
<p class="code"># wget &#8220;http://high5.net/postfixadmin/download.php?file=postfixadmin-2.1.0.tgz&#8221;<br />
# tar xvfz postfixadmin-2.1.0.tgz<br />
# cd postfixadmin-2.1.0<br />
# mysql -uroot -p &lt; DATABASE_MYSQL.TXT</p>
</blockquote>
<p>Now over to the next section.</p>
<h2>Postfix</h2>
<p>The database part is finished for now, and the time has now come for the Postfix SMTP daemon to be installed. When debconf asks you which configuration to install, just choose &#8220;no configuration&#8221;, since we will do everything by hand:</p>
<blockquote>
<p class="code"># apt-get install postfix postfix-tls postfix-mysql</p>
</blockquote>
<p>The first thing to do is figuring out where you want the virtual home directory located. Good places for this could be /home/virtual, /var/mail/virtual, /var/spool/postfix/virtual and so on. In this guide I will use /home/virtual as a base for virtual users. We need to let Postfix be the owner of this directory, so do the following:</p>
<blockquote>
<p class="code"># cd /home<br />
# mkdir virtual<br />
# chown -R postfix:postfix virtual<br />
# chmod -R 771 virtual</p>
</blockquote>
<p>Let&#8217;s get cracking on the Postfix configuration now shall we. We need to add lots of configuration options to several files in the /etc/postfix directory.</p>
<p>/etc/postfix/main.cf:</p>
<blockquote>
<p class="code"># Set your hostname<br />
myhostname = mail.example.com<br />
mynetworks = 127.0.0.0/8<br />
smtpd_banner = $myhostname ESMTP ready<br />
# If you need to relay outgoing mail via your ISP, set it here<br />
#relayhost = smtprelay.example.com<br />
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf<br />
# Make sure that the following number is the GID for the postfix user<br />
virtual_gid_maps = static:102<br />
virtual_mailbox_base = /home/virtual<br />
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf<br />
virtual_mailbox_limit = 512000000<br />
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf<br />
virtual_minimum_uid = 100<br />
virtual_transport = virtual<br />
# Make sure that the following number is the UID for the postfix user<br />
virtual_uid_maps = static:102<br />
virtual_create_maildirsize = yes<br />
virtual_mailbox_extended = yes<br />
virtual_mailbox_limit_maps =<br />
mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf<br />
virtual_mailbox_limit_override = yes<br />
virtual_maildir_limit_message = Sorry, the user&#8217;s maildir has overdrawn his<br />
diskspace quota, please try again later.<br />
virtual_overquota_bounce = yes<br />
relay_domains = proxy:mysql:/etc/postfix/mysql_relay_domains_maps.cf<br />
smtpd_recipient_restrictions =<br />
permit_mynetworks,<br />
permit_sasl_authenticated,<br />
reject_non_fqdn_hostname,<br />
reject_non_fqdn_sender,<br />
reject_non_fqdn_recipient,<br />
reject_unauth_destination,<br />
reject_unauth_pipelining,<br />
reject_invalid_hostname,<br />
reject_rbl_client opm.blitzed.org,<br />
reject_rbl_client list.dsbl.org,<br />
reject_rbl_client bl.spamcop.net,<br />
reject_rbl_client sbl-xbl.spamhaus.org,<br />
permit<br />
smtpd_sasl_auth_enable = yes<br />
smtpd_sasl_local_domain = $myhostname<br />
smtpd_sasl_security_options = noanonymous<br />
smtpd_tls_cert_file = /etc/postfix/sasl/smtpd.cert<br />
smtpd_tls_key_file = /etc/postfix/sasl/smtpd.key<br />
tls_random_source = dev:/dev/urandom<br />
tls_daemon_random_source = dev:/dev/urandom<br />
smtpd_use_tls = yes<br />
broken_sasl_auth_clients = yes<br />
#content_filter=smtp-amavis:[127.0.0.1]:10024<br />
max_use = 10</p>
</blockquote>
<p>/etc/postfix/mysql_virtual_alias_maps.cf:</p>
<blockquote>
<p class="code">user = postfix<br />
password = postfix<br />
hosts = localhost<br />
dbname = postfix<br />
table = alias<br />
select_field = goto<br />
where_field = address</p>
</blockquote>
<p>/etc/postfix/mysql_virtual_domains_maps.cf:</p>
<blockquote>
<p class="code">user = postfix<br />
password = postfix<br />
hosts = localhost<br />
dbname = postfix<br />
table = domain<br />
select_field = description<br />
where_field = domain<br />
#additional_conditions = and backupmx = &#8217;0&#8242; and active = &#8217;1&#8242;</p>
</blockquote>
<p>/etc/postfix/mysql_virtual_mailbox_maps.cf:</p>
<blockquote>
<p class="code">user = postfix<br />
password = postfix<br />
hosts = localhost<br />
dbname = postfix<br />
table = mailbox<br />
select_field = maildir<br />
where_field = username<br />
#additional_conditions = and active = &#8217;1&#8242;</p>
</blockquote>
<p>/etc/postfix/mysql_virtual_mailbox_limit_maps.cf:</p>
<blockquote>
<p class="code">user = postfix<br />
password = postfix<br />
hosts = localhost<br />
dbname = postfix<br />
table = mailbox<br />
select_field = quota<br />
where_field = username<br />
#additional_conditions = and active = &#8217;1&#8242;</p>
</blockquote>
<p>/etc/postfix/mysql_relay_domains_maps.cf:</p>
<blockquote>
<p class="code">user = postfix<br />
password = postfix<br />
hosts = localhost<br />
dbname = postfix<br />
table = domain<br />
select_field = domain<br />
where_field = domain<br />
additional_conditions = and backupmx = &#8217;1&#8242;</p>
</blockquote>
<p>Now over to the next section.</p>
<h2>SASL2</h2>
<p>For the SMTP authentication to work, the configuration file for SASL2 must be added. Here you can change everything about how the Postfix server behave in the authentication procedure. First you need to install the Sasl2 application:</p>
<blockquote>
<p class="code"># apt-get install sasl2-bin libsasl2 libsasl2-modules libsasl2-modules-sql</p>
</blockquote>
<p>/etc/postfix/sasl/smtpd.conf:</p>
<blockquote>
<p class="code">pwcheck_method: auxprop<br />
auxprop_plugin: sql<br />
sql_engine: mysql<br />
mech_list: LOGIN<br />
sql_hostnames: localhost<br />
sql_user: postfix<br />
sql_passwd: postfix<br />
sql_database: postfix<br />
sql_select: SELECT password FROM mailbox WHERE username = &#8216;%u@%r&#8217;</p>
</blockquote>
<p>Create the certificates for the Postfix server. Just make sure that the Common Name equals the mail server hostname:</p>
<blockquote>
<p class="code"># openssl genrsa -out server.key 1024<br />
# openssl req -new -key server.key -x509 -out server.cert</p>
</blockquote>
<p>Now over to the next section.</p>
<h2>Courier IMAP</h2>
<p>The Courier IMAP daemon needs to be told that it should use the postfix database for authentication. Note that there must not be ANY spaces in authmysqlrc, only tabs! Also, make sure that the UID and GID fields are according to the postfix user.</p>
<p>Begin by installing the IMAP server:</p>
<blockquote>
<p class="code"># apt-get install courier-imap-ssl</p>
</blockquote>
<p>/etc/courier/authmysqlrc:</p>
<blockquote>
<p class="code">#DEFAULT_DOMAIN example.net<br />
MYSQL_CRYPT_PWFIELD password<br />
MYSQL_DATABASE postfix<br />
MYSQL_GID_FIELD 102<br />
MYSQL_HOME_FIELD &#8216;/home/virtual&#8217;<br />
MYSQL_LOGIN_FIELD username<br />
MYSQL_MAILDIR_FIELD maildir<br />
MYSQL_NAME_FIELD name<br />
MYSQL_OPT 0<br />
MYSQL_PASSWORD postfix<br />
#MYSQL_PORT 0<br />
MYSQL_QUOTA_FIELD quota<br />
MYSQL_SERVER localhost<br />
MYSQL_SOCKET /var/run/mysqld/mysqld.sock<br />
MYSQL_UID_FIELD 102<br />
MYSQL_USERNAME postfix<br />
MYSQL_USER_TABLE mailbox<br />
#MYSQL_WHERE_CLAUSE server=&#8217;mailhost.example.com&#8217;</p>
</blockquote>
<p>Now over to the next section.</p>
<h2>Postfix admin</h2>
<p>Copy the Postfix admin directory to a web directory and read the installation instructions. Now your server should be working, but for simple webmail access Squirrelmail is the way to go.</p>
<h2>Squirrelmail</h2>
<p>Download the latest version of Squirrelmail and unpack it to an SSL enabled webspace. Configure it to use localhost as SMTP and IMAP, and set the IMAP server to courier. Good plugins are the following. (TODO: Add links to plugins)</p>
<ul>
<li>address_add</li>
<li>compatibility</li>
<li>notes</li>
<li>quicksave</li>
<li>sent_confirmation</li>
<li>check_quota</li>
<li>gpg (development version)</li>
<li>retrieveuserdata</li>
<li>BayesSpam</li>
</ul>
<h2>Quota support</h2>
<p>Note that this step is optional, but if you have lots of users, quota is necessary. Postfix in Debian doesn&#8217;t support virtual quouta out of the box. This isn&#8217;t a big deal. Just make sure that you have corresponding deb-src entries in your /etc/apt/sources.list file. Don&#8217;t forget to run apt-get update after to download the latest package information. To patch the Postfix source, do the following:</p>
<blockquote>
<p class="code"># apt-get source postfix<br />
# apt-get build-dep postfix<br />
# wget http://web.onda.com.br/nadal/postfix/VDA/postfix-2.1.5-trash.patch.gz<br />
# zcat postfix-2.1.5-trash.patch.gz | patch -p0<br />
# cd postfix-2.1.5<br />
# dpkg-buildpackage -rfakeroot -uc -b<br />
# cd ..<br />
# dpkg &#8211;install postfix*.deb</p>
</blockquote>
<p>The new Postfix packages should now be installed and the quota should now be working!</p>
<h2>IMAP Proxy Daemon</h2>
<p>Since Squirrelmail is stateless, it makes a new connection to the IMAP server every time it need some data. If you have lots of users accessing the IMAP server simultaneous, this can have a tremendous impact on performance. To remedy this proxy servers can be used. To install an IMAP proxy in Debian, do the following:</p>
<blockquote>
<p class="code"># apt-get install imapproxy</p>
</blockquote>
<p>You will need to change the configuration somewhat, and file to edit is /etc/imapproxy.conf so open it up with your favourite editor and make it look like the following.</p>
<p>/etc/imapproxy.conf:</p>
<blockquote>
<p class="code">server_hostname localhost<br />
cache_size 3072<br />
listen_port 144<br />
server_port 143<br />
cache_expiration_time 900<br />
proc_username nobody<br />
proc_groupname nogroup<br />
stat_filename /var/run/pimpstats<br />
protocol_log_filename /var/log/imapproxy_protocol.log<br />
syslog_facility LOG_MAIL<br />
send_tcp_keepalives no<br />
enable_select_cache no<br />
foreground_mode no</p>
</blockquote>
<p>Now start the daemon and change the IMAP server port in Squirrelmail to 144, and now your IMAP connections will be cached and will speed up Squirrelmail.</p>
<h2>References</h2>
<p><a title="Read another excellent guide" onclick="pageTracker._trackPageview('/outgoing/postfixwiki.org/index.php?title=Virtual_Users_and_Domains_with_Courier-IMAP_and_MySQL&amp;referer=');pageTracker._trackPageview('/outgoing/postfixwiki.org/index.php?title=Virtual_Users_and_Domains_with_Courier-IMAP_and_MySQL&amp;referer=http://johnny.chadda.se/2005/04/30/postfix-howto/');" href="http://postfixwiki.org/index.php?title=Virtual_Users_and_Domains_with_Courier-IMAP_and_MySQL">Virtual Users and Domains with Courier-IMAP and MySQL</a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnny.chadda.se/article/postfix-howto/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
	</channel>
</rss>
