<?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>No pain no gain &#187; Postfix</title>
	<atom:link href="http://www.dikant.de/category/postfix/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dikant.de</link>
	<description>Personal blog of Peter Dikant</description>
	<lastBuildDate>Sun, 23 May 2010 20:57:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Setting up a spamsafe Postfix server</title>
		<link>http://www.dikant.de/2007/08/11/setting-up-a-spamsafe-postfix-server/</link>
		<comments>http://www.dikant.de/2007/08/11/setting-up-a-spamsafe-postfix-server/#comments</comments>
		<pubDate>Sat, 11 Aug 2007 12:40:00 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Postfix]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.dikant.de/2007/08/11/setting-up-a-spamsafe-postfix-server/</guid>
		<description><![CDATA[I am currently in the process of upgrading my webserver to Debian Etch. In the past I have been using Debian Sarge with Plesk as an administration desktop. Plesk is very convenient, but it is also a memory hog and &#8230; <a href="http://www.dikant.de/2007/08/11/setting-up-a-spamsafe-postfix-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am currently in the process of upgrading my webserver to <a href="http://www.debian.org/" target="_blank">Debian Etch</a>. In the past I have been using Debian Sarge with <a href="http://www.swsoft.com/plesk/" target="_blank">Plesk</a> as an administration desktop. Plesk is very convenient, but it is also a memory hog and a performance killer, so I decided to go on without a web based administration tool and configure every service manually. This has the advantage that the system will be more secure and easier to update. The downside is a little bit more work in the beginning. During the next couple of postings I will document the configuration of the various services I have running on that server.</p>
<p>In this first post I will start with the mail service for which I choose the <a href="http://www.postfix.org/" target="_blank">Postfix</a> daemon together with <a href="http://www.policyd-weight.org/" target="_blank">policyd-weight</a> for spam filtering and <a href="http://www.dovecot.org/" target="_blank">Dovecot</a> as an IMAP and POP3 server. Authentication will be done with the SASL daemon against the standard user database. This is not really suited for large mail installations with a lot of users, but if you have to deal with only a couple of mail users, it is really easy to administrate.</p>
<p><span id="more-23"></span></p>
<p>This descriptions is based on the <a href="http://holl.co.at/howto-email/" target="_blank">Postfix tutorial</a> of Gerald Holt and Kain Anderer. Thanks for the great work!</p>
<p>Installing all required components is a breeze on a Debian system. During the installation your current mail daemon will be removed in favor of Postfix:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> postfix policyd-weight dovecot-imapd dovecot-pop3d sasl2-bin libsasl2-modules</pre></div></div>

<p>First let&#8217;s create a configuration file for policyd:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">policyd-weight defaults <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>policyd-weight.conf</pre></div></div>

<p>The default configuration is fine for us and we don&#8217;t need to change it. If you experience poor spam filtering results, you could modify the above configuration file to better suite your needs.</p>
<p>Next on the list is Dovecot. The configuration file <code>/etc/dovecot/dovecot.conf</code> needs to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xxx" style="font-family:monospace;">protocols =  imap imaps pop3 pop3s
disable_plaintext_auth = no
log_timestamp = &quot;%Y-%m-%d %H:%M:%S &quot;
ssl_cert_file = /etc/ssl/certs/dovecot.pem
ssl_key_file = /etc/ssl/private/dovecot.pem
mail_location = maildir:%h/Maildir
mail_extra_groups = mail
protocol imap {
}
protocol pop3 {
  pop3_uidl_format = %08Xu%08Xv
}
auth default {
  mechanisms = plain
  passdb shadow {
  }
  userdb passwd {
  }
  user = root
}
dict {
}
plugin {
}</pre></div></div>

<p>This will enable secure and plaintext logins with IMAP, IMAPS, POP3 and POP3S. If you want to restrict access to only encrypted and secure logins you need to change the following two settings:</p>

<div class="wp_syntax"><div class="code"><pre class="xxx" style="font-family:monospace;">protocols =  imaps pop3s
disable_plaintext_auth = yes</pre></div></div>

<p>The login credentials will be checked against the shadow user database.</p>
<p>Now we need to setup SASL to enable authentication checks in Postfix. First, we will configure the SASL daemon using the configuration file <code>/etc/default/saslauthd</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xxx" style="font-family:monospace;">START=yes
MECHANISMS=&quot;shadow&quot;
MECH_OPTIONS=&quot;&quot;
THREADS=2
OPTIONS=&quot;-m /var/spool/postfix/var/run/saslauthd&quot;
PWDIR=&quot;/var/spool/postfix/var/run/saslauthd&quot;
PIDFILE=&quot;/var/spool/postfix/var/run/${NAME}/saslauthd.pid&quot;</pre></div></div>

<p>Now create some directories inside the Postfix chroot environment and add postfix to the sasl usergroup:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <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<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>saslauthd
dpkg-statoverride <span style="color: #660033;">--add</span> root sasl <span style="color: #000000;">710</span> <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<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>saslauthd
adduser postfix sasl</pre></div></div>

<p>The last step to enable SASL authentication is to create the file <code>/etc/postfix/sasl/smtpd.conf</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xxx" style="font-family:monospace;">saslauthd_path: /var/run/saslauthd/mux
pwcheck_method: saslauthd
mech_list: plain login</pre></div></div>

<p>Before we edit the configuration file for Postfix, we need to create SSL certificates for secure SMTP connections:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl genrsa <span style="color: #660033;">-out</span> mail.key <span style="color: #000000;">2048</span>
openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-key</span> mail.key <span style="color: #660033;">-out</span> mail.csr
openssl x509 <span style="color: #660033;">-req</span> <span style="color: #660033;">-days</span> <span style="color: #000000;">4312</span> <span style="color: #660033;">-in</span> mail.csr <span style="color: #660033;">-out</span> mail.cert <span style="color: #660033;">-signkey</span> mail.key</pre></div></div>

<p>When filling out the certificate data you need to make sure, that you enter your fully qualified domain name in the field CN. Else you will get a warning about a wrong certificate every time you try to send email.</p>
<p>Now edit the main Postfix configuration file <code>/etc/postfix/main.cf</code>. It should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xxx" style="font-family:monospace;"># See /usr/share/postfix/main.cf.dist for a commented, more complete version# Debian specific:  Specifying a file name will cause the first# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP Mailserver
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
&nbsp;
# Uncomment the next line to generate &quot;delayed mail&quot; warnings
#delay_warning_time = 4h
&nbsp;
# TLS parameters
smtpd_tls_cert_file=/etc/postfix/mail.cert
smtpd_tls_key_file=/etc/postfix/mail.key
smtpd_use_tls=yes
smtpd_enforce_tls = no
smtpd_tls_auth_only = no
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache
&nbsp;
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
myhostname = FULL.DOMAIN.NAME
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost.$mydomain, $mydomain
relayhost =
mynetworks = 127.0.0.0/8
#mailbox_command = procmail -a &quot;$EXTENSION&quot;
mailbox_size_limit = 0
message_size_limit = 20480000
recipient_delimiter = +
inet_interfaces = all
&nbsp;
smtpd_helo_required = yes
smtpd_helo_restrictions = reject_invalid_hostname
smtpd_recipient_restrictions = permit_mynetworks, reject_unknown_recipient_domain, permit_sasl_authenticated, reject_unauth_destination, check_policy_service inet:127.0.0.1:12525
smtpd_sender_restrictions = reject_unknown_address
smtpd_client_restrictions = reject_invalid_hostname
strict_rfc821_envelopes = yes
&nbsp;
home_mailbox = Maildir/
&nbsp;
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
smtp_sasl_auth_enable = no
broken_sasl_auth_clients = yes
virtual_alias_domains = COLON SEPARATED LIST OF YOUR DOMAINS
virtual_alias_maps = hash:/etc/postfix/virtual_domains
virtual_mailbox_limit = 0</pre></div></div>

<p>In the above file you need to replace <strong>FULL.DOMAIN.NAME</strong> with your fully qualified domain name and <strong>COLON SEPARATED LIST OF YOUR DOMAINS</strong> with a list of all the domains you want to receive mails for.</p>
<p>Once this is done you can restart all services:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>policyd-weight restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>dovecot restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>saslauthd restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>postfix restart</pre></div></div>

<p><strong>Adding new mail users</strong></p>
<p>Create the user (in this example with the login &#8220;joe&#8221;):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser <span style="color: #660033;">--shell</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> joe</pre></div></div>

<p>Map email addresses to the user by editing the file <code>/etc/postfix/virtual_domains</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xxx" style="font-family:monospace;">joe.sample@mydomain.com    joe
joe@seconddomain.net         joe</pre></div></div>

<p>Rebuild the mappings database:</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>virtual_domains</pre></div></div>

<p>That&#8217;s it! You now have secure base mail configuration which does not allow mail relaying without logging in with a valid user account. The mails will be stored in the Maildir inside each users home folder and best of all thanks to policyd-weight most of the spam mails will be rejected by the mailserver. If you need even better spam filtering you could also integrate <a href="http://spamassassin.apache.org/" target="_blank">Spamassassin</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dikant.de/2007/08/11/setting-up-a-spamsafe-postfix-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
