<?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>nikrivers.com &#187; mail server</title>
	<atom:link href="http://www.nikrivers.com/tag/mail-server/feed" rel="self" type="application/rss+xml" />
	<link>http://www.nikrivers.com</link>
	<description></description>
	<lastBuildDate>Tue, 07 Sep 2010 16:42:12 +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>Netgear DG834G and NAT loopback</title>
		<link>http://www.nikrivers.com/2009/10/26/netgear-dg834g-and-nat-loopback</link>
		<comments>http://www.nikrivers.com/2009/10/26/netgear-dg834g-and-nat-loopback#comments</comments>
		<pubDate>Mon, 26 Oct 2009 21:13:33 +0000</pubDate>
		<dc:creator>Nik</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Techie Stuff]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mail server]]></category>
		<category><![CDATA[nat loopback]]></category>
		<category><![CDATA[netgear dg834g]]></category>
		<category><![CDATA[ntp]]></category>
		<category><![CDATA[pda]]></category>
		<category><![CDATA[router]]></category>
		<category><![CDATA[tcp port 80]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.nikrivers.com/?p=591</guid>
		<description><![CDATA[UPDATE 18th April 2010: Netgear have since released a firmware update for the DG834Gv4 which supports NAT loopback.  It took them long enough! Yesterday I made the decision (read: mistake) to update my Netgear DG834G router (hardware v4, firmware v5.01.09) to firmware v5.01.14 &#8211; and, as is the way with these things, it brought trouble.  After the upgrade I [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff6600;"><strong>UPDATE 18th April 2010:</strong> Netgear have since released a </span><a href="http://kb.netgear.com/app/answers/detail/a_id/13354" target="_blank"><span style="color: #ff6600;">firmware update</span></a><span style="color: #ff6600;"> for the DG834Gv4 which supports NAT loopback.  It took them long enough!</span></p>
<p>Yesterday I made the decision (read: mistake) to update my Netgear DG834G router (hardware v4, firmware v5.01.09) to firmware v5.01.14 &#8211; and, as is the way with these things, it brought trouble.  After the upgrade I couldn&#8217;t reach <a href="http://www.nikrivers.com">www.nikrivers.com</a> from the LAN side of the router.</p>
<p>The problem is caused by the way the router handles traffic coming from an internal IP address and destined for the WAN (i.e. external) IP address.  In this situation it requires that the router first transfers the traffic from the internal network to the external network, and then immediately passes it back whilst applying any firewall or routing rules that are relevant to incoming external traffic.</p>
<p><span id="more-591"></span>This behaviour is called &#8216;NAT loopback&#8217;, and it seems the vast majority of routers built for the home market have this ability turned off, or do not have the ability at all.  It can be a big problem if you host a website and wish to access that same website using its domain name.  The domain name will resolve to the WAN IP address of your router, and any traffic headed there (such as an HTTP GET request on port 80) from the internal network will be ignored by the router.</p>
<p>There are a few ways to solve this, but none of them are ideal.</p>
<ol>
<li>Use the server name instead of the domain name to access your website</li>
<li>Modify the list of known network hosts on each client to point your domain name straight to the server in question.</li>
<li>Run your own DNS server, using a view to return the server&#8217;s local IP address to requests for your domain name originating from your network.</li>
</ol>
<p>Of course, the situation gets more complex if you&#8217;re also using your router to send TCP traffic on port 80 to your webserver and UDP traffic on port 8668 to a game server.</p>
<p>The solution is to get NAT loopback working on your router.  With some routers, such as the Touchspeed 535 as provided by Be Broadband, this feature can be enabled using a <a href="http://thicksliced.blogspot.com/2006/08/speedtouch-and-nat-loopback.html" target="_blank">simple CLI command</a>.  For other routers, such as the Netgear DG834G, it&#8217;s not quite so easy.</p>
<p>For the purposes of this post I&#8217;ll assume the internal network is on the 192.168.0.x range, the router is 192.168.0.254, and the web server is 192.168.0.1.  <strong>You will need to modify these IP addresses according to your own network setup</strong>.</p>
<p>The first thing to do is to enable debug mode on the router.  Simply go to <a href="http://192.168.0.254/setup.cgi?todo=debug">http://192.168.0.254/setup.cgi?todo=debug</a> and you&#8217;ll be rewarded with an appropriate message, &#8220;Debug Enable!&#8221;.  Nice.</p>
<p>Now connect to the router with &#8216;telnet 192.168.0.254&#8242; to gain access to the router&#8217;s cut-down installation of Linux.  All that is required is to add one additional entry to the router&#8217;s iptables (which is a standard Linux feature; <a href="http://www.google.com/search?q=iptables+tutorial" target="_blank">Google it</a> or more info).  Type the following, amending any IP addresses according to the network setup:</p>
<blockquote><p>iptables -t nat -A POSTROUTING -d 192.168.0.1 -s 192.168.0.0/24 -p tcp &#8211;dport 80 -j SNAT &#8211;to 192.168.0.254</p></blockquote>
<p>This adds a rule to the POSTROUTING chain on the nat table which applies to all TCP traffic on port 80 (HTTP) coming from the private network and headed to the router.  The rule redirects the traffic to the server, and then processing jumps to the SNAT chain.</p>
<p>If the server is more than just a simple web server, such as an NTP server or mail server as well, the above step needs to be performed (changing the -p and &#8211;dport parameters accordingly) for each port and protocol combination you require.  Alternatively, those parameters could be omitted altogether, which will allow all traffic types on all ports through:</p>
<blockquote><p>iptables -t nat -A POSTROUTING -d 192.168.0.1 -s 192.168.0.0/24 -j SNAT &#8211;to 192.168.0.254</p></blockquote>
<p>If you do this, I recommend you run a firewall on your server, with only the appropriate ports opened.</p>
<p>There is more information in <a href="http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO-10.html" target="_blank">section 10</a> of Rusty Russell&#8217;s <a href="http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO.html" target="_blank">Linux 2.4 NAT Howto</a>.</p>
<p>Unfortunately, the iptables change isn&#8217;t retained when the router restarts, so it is necessary to go through the process every time &#8211; which is a pain in the backside.  Fortunately, however, the Netgear support website has a download link for previous firmware versions, so I downgraded my router back to <a href="http://kb.netgear.com/app/answers/detail/a_id/271" target="_blank">firmware v5.01.09</a> and everything worked fine again&#8211;including NAT loopback&#8211;with no iptables hack required.</p>
<h3>A robust solution with DNS</h3>
<p>Simply put, proper DNS is the best way to get around a router&#8217;s lack of/poorly implemented NAT loopback.</p>
<p>If you have the resources to host a website then you most likely also have the resources to host a DNS server for your internal network.  Simply create an ACL list describing all the clients on your internal network (probably as simple as specifying the CIDR block for your network, maybe something like 192.168.1.0/24).  Then create a view whose clients match that ACL, and define that view as a master DNS server for your website domain.  You then need to create a zone file for that domain &#8211; but instead of using an external IP for your webserver, use its internal IP.</p>
<p>All requests for other domains will be routed to the DNS forwarders, but requests for your webserver&#8217;s domain will be handled locally, and internal IP addresses will be returned.</p>
<p>The benefit is that you avoid traversing your gateway router to simply come back inside your network.  It doesn&#8217;t make sense that you rely on your gateway router to access a website within your own network.  In addition, the firewall on your router can be hardened to a much greater degree: for example, you needn&#8217;t leave FTP ports open on your router if you&#8217;re only connecting locally.  Or, to put it another way, you&#8217;re likely going to want to give yourself more access to your server than you want to give to the outside world; configuring a router&#8217;s firewall rules for this kind of conditional logic is simply asking for trouble.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nikrivers.com/2009/10/26/netgear-dg834g-and-nat-loopback/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Popular pages</title>
		<link>http://www.nikrivers.com/2009/03/07/popular-pages</link>
		<comments>http://www.nikrivers.com/2009/03/07/popular-pages#comments</comments>
		<pubDate>Sat, 07 Mar 2009 11:13:12 +0000</pubDate>
		<dc:creator>Nik</dc:creator>
				<category><![CDATA[Techie Stuff]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[linksys]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mail server]]></category>
		<category><![CDATA[nas]]></category>
		<category><![CDATA[nslu2]]></category>

		<guid isPermaLink="false">http://www.nikrivers.com/?p=398</guid>
		<description><![CDATA[This website is a sort of personal project, rather than a proper blog &#8211; the reason I make this distinction is because I usually don&#8217;t have anything interesting to say; at least, nothing that would be of any interest to anyone who doesn&#8217;t know me. Much like being able to tell (but not necessarily care) [...]]]></description>
			<content:encoded><![CDATA[<p>This website is a sort of personal project, rather than a proper blog &#8211; the reason I make this distinction is because I usually don&#8217;t have anything interesting to say; at least, nothing that would be of any interest to anyone who doesn&#8217;t know me.</p>
<p><span id="more-398"></span></p>
<p>Much like being able to tell (but not necessarily care) when I&#8217;m boring someone with a particular conversation, I use website analytics to see where website visitors come from, what they look at, and how frequently they return. Yes, some people come back. In fact, most people do. And the most popular pages are actually the<a href="http://www.nikrivers.com/linksys-nslu2/"> </a><a href="http://www.nikrivers.com/linksys-nslu2/" target="_self">NSLU2 guides</a> which describe how to configure a very small, low-power Linux server based on a Linksys NAS device.</p>
<p>I have no delusions about the overall importance of nikrivers.com; nobody knows about it, it doesn&#8217;t appear very high up in any Google results unless you search for my name, and even my mum keeps forgetting how to find it (though she also has to keep asking me how to find the Internet, because &#8220;it&#8217;s gone from my desktop&#8221;).</p>
<p>That said, 101 different people have visited my NSLU2 guides in the last 20 days alone, about a third of which are visitors who have never been to my website before. Even after Linksys has discontinued the NSLU2, it still remains popular as a web and mail server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nikrivers.com/2009/03/07/popular-pages/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linksys NSLU2: email with Postfix and Dovecot</title>
		<link>http://www.nikrivers.com/linksys-nslu2/email-with-postfix-and-dovecot</link>
		<comments>http://www.nikrivers.com/linksys-nslu2/email-with-postfix-and-dovecot#comments</comments>
		<pubDate>Tue, 22 Apr 2008 22:42:15 +0000</pubDate>
		<dc:creator>Nik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[linksys]]></category>
		<category><![CDATA[mail server]]></category>
		<category><![CDATA[nslu2]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://www.nikrivers.com/?page_id=38</guid>
		<description><![CDATA[I&#8217;m using Postfix as the mail transport agent (MTA) and Dovecot as the mail delivery agent (MDA), and the mail server will serve just one domain (for now). The domain will be served as a virtual host. This means that the mail users don&#8217;t need their own login account on the server, and additional domains [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using Postfix as the mail transport agent (MTA) and Dovecot as the mail delivery agent (MDA), and the mail server will serve just one domain (for now). The domain will be served as a virtual host. This means that the mail users don&#8217;t need their own login account on the server, and additional domains can be served in future with minimal changes.</p>
<p>Many thanks go to Raymond Mentjens (<a href="http://www.mentjens.nl">www.mentjens.nl</a>) for his help in fixing a few (actually, <em>quite</em> a few) errors, and for all his feedback while he followed this article.  He has also created his own guides in Dutch &#8211; so if you read Dutch better than English, you may want to take a look at his site.</p>
<h3>Versions</h3>
<p>This how-to guide was updated in May 2009 for compatibility with the following package versions:</p>
<ul>
<li>Postfix 2.3.6-3</li>
<li>Dovecot v1.2.0.beta1-2</li>
</ul>
<p>This how-to may also work with previous versions, but may require slight changes with respect to paths &#8211; for example, previous versions of Dovecot installed <strong>dovecot.conf</strong> to <strong>/opt/etc/dovecot.conf</strong>, but the latest version installs it to <strong>/opt/etc/dovecot/dovecot.conf</strong>.</p>
<h3>Install Postfix</h3>
<p>Issue the command:</p>
<blockquote><p>ipkg install postfix</p></blockquote>
<p>The Postfix installation automatically creates a new group called maildrop; check maildrop is created:</p>
<blockquote><p>more /etc/group</p></blockquote>
<p>If the group is not there, you will have to create it yourself. Also note that it might suddenly disappear, requiring you to add it manually. For both eventualities, see the notes below.</p>
<p>Now we&#8217;ll need to start editing the configuration files to customise Postfix to our needs.</p>
<blockquote><p>vi /opt/etc/postfix/master.cf</p></blockquote>
<p>Add -v to the end of the line that specifies the smtp daemon so it reads <strong>smtpd -v</strong> (the line you need to modify is the first in the table, just beneath several lines of comments). This enables verbose output to the log file, which you should monitor in a separate PuTTY window using the following command:</p>
<blockquote><p>tail -f /var/log/messages</p></blockquote>
<p>This will help give you an idea of when and why problems occur. Note that tail sometimes hangs, and if you don&#8217;t see log output when you think you should then it may be time to abort tail (with CTRL+C) and restart it.</p>
<p>Let&#8217;s edit the main Postfix configuration file:</p>
<blockquote><p>vi /opt/etc/postfix/main.cf</p></blockquote>
<p>And provide our own values for the following parameters:</p>
<blockquote><p>myhostname = &lt;your slug&#8217;s host name &#8211; eg. mail.yourdomain.com&gt;<br />
inet_interfaces = all<br />
proxy_interfaces = &lt;your external ip address&gt;<br />
mynetworks_style = subnet</p></blockquote>
<p>Before Postfix can be started, it needs to know where to deliver mail that is addressed to users such as root, postmaster, and other pseudo-accounts. The file that contains this mapping is /opt/etc/postfix/aliases. Edit the file:</p>
<blockquote><p>vi /opt/etc/postfix/aliases</p></blockquote>
<p>Uncomment the root alias, and provide the address where mail to root should be delivered (using your own address is a wise choice):</p>
<blockquote><p># Person who should get root&#8217;s mail. Don&#8217;t receive mail as root!<br />
root: &lt;your email address&gt;</p></blockquote>
<p>Now the file should be copied to <strong>/opt/etc/aliases</strong>, and turned into a hash file that postfix can read, using the <strong>newaliases</strong> tool. The output file is <strong>/opt/etc/aliases.db</strong>:</p>
<blockquote><p>cp /opt/etc/postfix/aliases /opt/etc/aliases<br />
newaliases</p></blockquote>
<p>Now start Postfix, keeping an eye on your second PuTTY window for any messages Postfix might emit.</p>
<blockquote><p>/opt/etc/init.d/S69postfix</p></blockquote>
<p>At various points you&#8217;ll need to change Postfix configuration, and Postfix will need to reload those changes. You can do this with:</p>
<blockquote><p>/opt/etc/init.d/S69postfix restart</p></blockquote>
<p>Or, if you don&#8217;t like to keep stopping and starting it, you can simply issue:</p>
<blockquote><p>postfix reload</p></blockquote>
<h3>Testing Postfix</h3>
<p>Use telnet to connect to your slug&#8217;s smtp port:</p>
<blockquote><p>telnet &lt;slug&#8217;s host name or IP address&gt; smtp</p></blockquote>
<p>Make sure you can send mail, by having the following conversation with Postfix:</p>
<blockquote><p>220 mail.yourdomain.com ESMTP Postfix<br />
mail from:some_user<br />
250 2.1.0 Ok<br />
rcpt to:&lt;an external email address you can check&gt;<br />
250 2.1.5 Ok<br />
data<br />
354 End data with &lt;CR&gt;&lt;LF&gt;.&lt;CR&gt;&lt;LF&gt;<br />
Subject:Test Mail 1<br />
This is a test message.<br />
.<br />
250 2.0.0 Ok: queued as EF7E4208003</p></blockquote>
<p>When you check the email address to which you sent your test mail, you&#8217;ll see it comes from some_user@mail.localdomain (or something similar, according to what you put in your postfix configuration file), and is generally badly formed. Don&#8217;t worry, a proper email client will provide the necessary data, whereas we only provided the bare minimum. Note that some mail servers may reject this test mail because the sender&#8217;s address is malformed (i.e. the domain doesn&#8217;t exist). In this case, you will need to use a valid-looking email address (such as some_user@test.com) or even your own address.</p>
<p>If you don&#8217;t receive the test email, you can check the postfix queue to see whether an error occured:</p>
<blockquote><p>postqueue -p</p></blockquote>
<p>And also delete any failed/stuck messages:</p>
<blockquote><p>postsuper -d &lt;queue_id&gt;</p></blockquote>
<p>On a side note, it&#8217;s a good demonstration of how easy it is to send untraceable spam. The IP address in the email header is the only indication of where the email originated; but this can be faked quite easily.</p>
<h3>Finalise Postfix Configuration</h3>
<p>There&#8217;s already a convenient user and group (both called mail) configured by the system which Postfix can use to manage the mail store, so all we need to do it find out the uid and gid.</p>
<blockquote><p>grep mail /etc/passwd</p></blockquote>
<p>The 3rd and 4th elements of the output are the uid and gid respectively. Write them down; we&#8217;ll need them in a minute.</p>
<p>We need a disk location for storing users&#8217; mail; I chose <strong>/var/spool/vmail</strong>, which seems as good as any. The following script creates the initial directory structure, along with the additional directories for user@yourdomain.com mail storage. The <strong>/var/spool</strong> directory didn&#8217;t exists on my system, so rather than checking to see if there was a more logical/suitable storage location elsewhere, I simply created it with brute force.</p>
<blockquote><p>mkdir /var/spool<br />
cd /var/spool<br />
mkdir vmail<br />
cd vmail<br />
mkdir yourdomain.com<br />
cd yourdomain.com<br />
mkdir user<br />
cd user<br />
mkdir new cur tmp</p></blockquote>
<p>Now the new directories need the right owners and permissions: <strong>root</strong> owns <strong>/var/spool</strong> (and gives full permission to everyone), whereas the <strong>vmail</strong> directory (and everything within it) is owned by <strong>mail</strong>, and only <strong>mail</strong> (and members of the <strong>mail</strong> group) have permissions.</p>
<blockquote><p>chmod ugo=rwx /var/spool<br />
chown -R mail:mail /var/spool/vmail<br />
chmod -R ug=rwx,o= /var/spool/vmail</p></blockquote>
<p>You can double-check this afterwards:</p>
<blockquote><p>ls -l -R /var/spool/vmail | more</p></blockquote>
<p>In order to use Dovecot&#8217;s SMTP AUTH mechanism, Postfix needs to know where Dovecot&#8217;s daemon socket is located. Currently it isn&#8217;t located anywhere, so that needs to be fixed:</p>
<blockquote><p>cp /opt/var/spool/postfix/private/anvil /opt/var/spool/postfix/private/auth<br />
chmod go=rw /opt/var/spool/postfix/private/auth<br />
chown mail:mail /opt/var/spool/postfix/private/auth</p></blockquote>
<p>Time to edit the postfix config again.</p>
<blockquote><p>vi /opt/etc/postfix/main.cf</p></blockquote>
<p>The config file isn&#8217;t set up with default values for virtual hosts, so these need to be added. We also tell Postfix that we&#8217;re using Dovecot for SMTP AUTH, and point it to the socket location we just created (relative to the queue directory). Note that as soon as we tell Postfix about the socket, it will grumble and complain (and fail to run) because Dovecot hasn&#8217;t created the socket yet. We&#8217;ll do that shortly.</p>
<blockquote><p># LOCAL CONFIG<br />
local_recipient_maps = $virtual_mailbox_maps<br />
# SMTP AUTH<br />
smtpd_sasl_type = dovecot<br />
smtpd_sasl_path = private/auth<br />
# VIRTUAL HOSTS<br />
# Config for virtual domains that are hosted by this server.<br />
virtual_mailbox_domains = /opt/etc/postfix/virtual-hosts<br />
virtual_mailbox_base = /var/spool/vmail<br />
virtual_mailbox_maps = hash:/opt/etc/postfix/virtual-maps<br />
virtual_uid_maps = static:&lt;mail uid&gt;<br />
virtual_gid_maps = static:&lt;mail gid&gt;<br />
virtual_minimum_uid = &lt;mail uid&gt;</p></blockquote>
<p>Replace <strong>&lt;mail uid&gt;</strong> and <strong>&lt;mail gid&gt;</strong> with the uid and gid you noted earlier on.</p>
<p>Now we are left with two files to create. The file <strong>/opt/etc/postfix/virtual-hosts</strong> should contain a list of all the domains you are hosting, one on each line. The file <strong>/opt/etc/postfix/virtual-maps</strong> defines the storage location for your mail users.</p>
<p>virtual-hosts:</p>
<blockquote><p>yourdomain.com</p></blockquote>
<p>virtual-maps:</p>
<blockquote><p>you@yourdomain.com yourdomain.com/you/<br />
me@yourdomain.com yourdomain.com/me/</p></blockquote>
<p>The second column is the storage path, relative to <strong>$virtual_mailbox_base</strong>. So mail for you@yourdomain.com will be stored in <strong>/var/spool/vmail/yourdomain.com/you</strong>. The trailing slash in the file is important, and specifies that the Maildir format of mail storage is to be used, as opposed than mbox. Maildir stores each mail as a separate file, which makes more sense to me than mbox, which stores all mail in one file.</p>
<p>We now turn <strong>/opt/etc/postfix/virtual-maps </strong>into a hash file, and give Postfix read permission:</p>
<blockquote><p>postmap /opt/etc/postfix/virtual-maps<br />
chmod o+r /opt/etc/postfix/virtual-maps.db</p></blockquote>
<p>You can now restart the server so your changes take effect, but bear in mind that the <strong>smptd</strong> process will crash if you try to connect to it &#8211; because the Dovecot socket doesn&#8217;t exist yet.</p>
<blockquote><p>/opt/etc/init.d/S69postfix restart</p></blockquote>
<h3>Install Dovecot</h3>
<blockquote><p>ipkg install dovecot</p></blockquote>
<p>First, a warning: Dovecot caused more trouble than anything I&#8217;ve done with the Slug so far. It&#8217;s easier to configure than Postfix, but easier to mess up, too!</p>
<p>For starters, you will definitely want to edit the Dovecot config to turn logging on:</p>
<blockquote><p>vi /opt/etc/dovecot/dovecot.conf</p></blockquote>
<p>At the start of the file insert the following parameters (we&#8217;ll be removing them again later):</p>
<blockquote><p>log_path = /var/log/dovecot<br />
info_log_path = /var/log/dovecot<br />
auth_debug = yes<br />
auth_verbose = yes</p></blockquote>
<p>Let&#8217;s tell Dovecot where mail can be found. Edit the mail_location parameter as follows. This tells Dovecot that mail for you@yourdomain.com can be found at <strong>/var/spool/vmail/yourdomain.com/you</strong>. Note that in older versions of Dovecot this setting was default_mail_env.</p>
<blockquote><p>mail_location = maildir:/var/spool/vmail/%d/%n</p></blockquote>
<p>Now we want to tell Dovecot about the STMP AUTH socket it needs to create. Find the auth default configuration block (about 80% of the way through the file) and add/edit the following configuration block inside the auth default block.</p>
<blockquote><p>socket listen {<br />
client {<br />
path = /opt/var/spool/postfix/private/auth<br />
mode = 0660<br />
user = mail<br />
group = mail<br />
}<br />
}</p></blockquote>
<p>This tells Dovecot what we&#8217;ve already told Postfix &#8211; now Dovecot knows to create the auth socket, and put it in the right location. We now need to tell Dovecot which users are allowed to use our SMTP server and where it can find their passwords. The relevant sections, <strong>passdb</strong> and <strong>userdb</strong>, already exist in the auth default block, and should be edited as follows.</p>
<blockquote><p>passdb passwd-file {<br />
args = /etc/passwd-mail<br />
}</p></blockquote>
<blockquote><p>userdb static {<br />
args = uid=&lt;mail uid&gt; gid=&lt;mail gid&gt;<br />
}</p></blockquote>
<p>The passdb section tells Dovecot to use a passwd-like file located at <strong>/etc/passwd-mail</strong> to check users&#8217; passwords. The userdb section is usually used in a similar way to look up valid email users &#8211; but since we don&#8217;t need another look up, we can use the &#8216;static&#8217; mechanism, in which case Dovecot will rely on the passdb section for both valid users AND passwords.</p>
<p>Don&#8217;t forget to replace <strong>&lt;mail uid&gt;</strong> and <strong>&lt;mail gid&gt;</strong> with the uid and gid of your mail user and group. If your uid is less than 500 (which, if you used the built-in mail account, it is) you will need to change the <strong>first_valid_uid </strong>value in the config file to something less than or equal to the uid you are using.</p>
<p>The last thing involving the configuration file is to tell Dovecot which protocol we want clients to be able to use. By default, Dovecot supports only IMAP &#8211; but I prefer POP3.</p>
<blockquote><p>#protocols = imap imaps<br />
protocols = pop3</p></blockquote>
<p>IMAP has some significant <a href="http://en.wikipedia.org/wiki/IMAP#Advantages_over_POP3" target="_blank">advantages</a> over POP3, providing an Exchange-like environment for email, but it also has its <a href="http://en.wikipedia.org/wiki/IMAP#Disadvantages_of_IMAP" target="_blank">disadvantages</a>. If you&#8217;re happy to store all your email locally, you&#8217;re only going to connect from a single client, and prefer ISP-like email, the more common POP3 should be just fine.</p>
<p>Now we need to create the passwd-like lookup file.</p>
<blockquote><p>vi /etc/passwd-mail</p></blockquote>
<p>It&#8217;s content will be of the format &lt;username&gt;:{encryption_scheme}password, for example:</p>
<blockquote><p>you@yourdomain.com:{plain}yourpassword</p></blockquote>
<p>The {plain} directive denotes that the password is in plain text; this overrides whatever encryption Dovecot might be expecting &#8211; DES in this case (the same as you&#8217;d find in /etc/passwd). If you DES-encrypt your password before putting it in <strong>/etc/passwd-mail</strong> you do not need an {encryption_scheme} directive.</p>
<p>By default, the dovecot-auth process runs as user admin, which is a member of the group administrators. You can change this by editing dovecot.conf, but it is not necessary. The admin user needs read privileges on the mail password file, so give this permission to the group to which user admin belongs:</p>
<blockquote><p>chown root:administrators /etc/passwd-mail<br />
chmod g=r /etc/passwd-mail</p></blockquote>
<p>Now you&#8217;re ready to start Dovecot. You may like to open a separate session on your Slug and run <strong>tail -f /var/log/dovecot</strong> to monitor what&#8217;s going on:</p>
<blockquote><p>/opt/etc/init.d/S90dovecot start</p></blockquote>
<p>If this produces errors, double-check the edits you made to /opt/etc/dovecot/dovecot.conf &#8211; a common problem is the mismatching of curly braces { and }.</p>
<h3>Testing Dovecot</h3>
<p>Now use telnet to connect to Dovecot on your slug:</p>
<blockquote><p>telnet &lt;slug&#8217;s host name or IP address&gt; pop3</p></blockquote>
<p>You can have the following conversation with it:</p>
<blockquote><p>+OK Dovecot ready.<br />
user you@yourdomain.com<br />
+OK<br />
pass wrongpassword<br />
-ERR Authentication failed.<br />
user you@yourdomain.com<br />
+OK<br />
pass yourpassword<br />
+OK Logged in.</p></blockquote>
<p>Great. You now have a working email server which offers SMTP without being an open relay, and provides POP3 to the user(s) you specified.</p>
<p>If Dovecot crashes when you authenticate, and logs &#8220;<em>Panic: POP3(you@yourdomain.com): Trying to allocate 0 bytes</em>&#8220;, you have found a kown bug with the Dovecot 1.2 beta 1 release (the latest release that is available through ipkg). Although this doesn&#8217;t prevent you from using Dovecot, most email clients will complain that the connection to the POP3 server was prematurely terminated. A patch is available at <a href="http://hg.dovecot.org/dovecot-1.2/rev/22d70947597c">http://hg.dovecot.org/dovecot-1.2/rev/22d70947597c</a>, but I have not had a chance to try it.</p>
<h3>Finally</h3>
<p>Don&#8217;t forget to turn off verbose logging for Postfix and Dovecot. For Postfix, remove the &#8216;-v&#8217; smtpd parameter from /opt/etc/postfix/master.cf, and for Dovecot remove the first four lines of /opt/etc/dovecot/dovecot.conf (log_path, info_path, auth_debug and auth_verbose).</p>
<h3>Limitations</h3>
<p>The one big limitation with this set up is that the administration of mail users involves a lot of work. Every time you add a user you must create the relevant entry in virtual-maps, create the user&#8217;s mail delivery directory structure, and set permissions. The mitigation against this drawback is that you (probably) won&#8217;t be using your Slug as a mail server for more than a handful of email addresses &#8211; any heavier use would probably require a more significant investment, and hence more powerful tools.</p>
<h3>Notes</h3>
<p><strong>Group &#8216;maildrop&#8217; disappears</strong><br />
It seems that, at some point, the maildrop group &#8216;disappears&#8217; from <strong>/etc/group</strong>. It may be something to do with the fact that <strong>/etc/group</strong> is a symbolic link to <strong>/share/flash/conf/group</strong>, and thus may be more closely-managed by the Slug than it appears. Regardless, it causes SMTP clients to be unable to connect (because Postfix fails to start), and Postfix emits an appropriate message to <strong>/var/log/message</strong>.</p>
<p>This can be resolved by manually recreating the appropriate entry in <strong>/etc/group </strong>for maildrop:</p>
<blockquote><p>maildrop:x:69:</p></blockquote>
<p>Fortunately, it seems that this is only required once.</p>
<p><strong>Using your ISP&#8217;s SMTP server</strong><br />
Some ISPs may require that any email you send is relayed through their SMTP server; in this case you will likely need to add the <em>relayhost</em> parameter to your <strong>main.cf</strong> as well (although this wasn&#8217;t necessary in my case). Documentation for this parameter can be found on the Postfix website at <a href="http://www.postfix.org/postconf.5.html#relayhost" target="_blank">http://www.postfix.org/postconf.5.html#relayhost</a>. Explicit authentication with your ISP&#8217;s SMTP server is usually not required as long as you are connected to the Internet via that ISP&#8217;s connection (either dial-up or always-on).</p>
<p><strong>Encryption of stored passwords</strong><br />
When installing and configuring Dovecot, I store email users&#8217; passwords in plain text. If you want to store passwords in an encrypted format, see <a href="http://wiki.dovecot.org/Authentication/PasswordSchemes">http://wiki.dovecot.org/Authentication/PasswordSchemes</a> for an explanation.</p>
<h3>Next Steps</h3>
<p><strong>Firewall</strong><br />
If you have a firewall or NAT between your Slug and the outside world (which is highly recommended) and you want to access your email from anywhere, you will need to configure your firewall or NAT to forward ports 25 (smtp) and 110 (pop3) to your Slug.</p>
<p>Of course, if you open up your email server to the rest of the world, you may want to make sure it can&#8217;t be abused. Go to <a href="http://www.abuse.net/relay.html">http://www.abuse.net/relay.html</a>, provide your external IP address, and let it test your email server for being an open relay.</p>
<p><strong>Date/Time</strong><br />
It&#8217;s a good idea to keep your Slug&#8217;s time accurate so that the mail server can timestamp email correctly. This can be done by running an NTP client, which will synchronise the Slug&#8217;s time with reliable time servers around the world, or by running an NTP server, which will synchronise the Slug&#8217;s time AND allow you to synchronise your network computers&#8217; time with the Slug.</p>
<p>Due to a glitch in the Slug, this isn&#8217;t as straight-forward as it could be &#8211; but it&#8217;s not beyond anyone with enough patience to work with vi.</p>
<p>Detailed instructions are <a href="http://www.nikrivers.com/linksys-nslu2/time-server-with-ntp">here</a>.</p>
<p><strong>SSL/TLS</strong><br />
These instructions give you a working email server, but all authentication is performed using plain text. That means that anyone using a network sniffer in the right place at the right time could steal your usernames and passwords as you transmit them to the server.</p>
<p>Rather than configure authentication mechanisms that prevent this (and which, to be honest, look difficult to configure), we can encrypt the whole of the communication between client and server using SSL and TLS.</p>
<p>Detailed instructions are <a href="http://www.nikrivers.com/linksys-nslu2/ssl-and-tls-for-postfix-and-dovecot">here</a>.</p>
<h3>Useful Links</h3>
<p><a href="http://www.postfix.org/">http://www.postfix.org/</a><br />
<a href="http://www.dovecot.org/">http://www.dovecot.org/</a><br />
<a href="http://www.nslu2-linux.org/">http://www.nslu2-linux.org/</a><br />
<a href="http://www.howtoforge.com/linux_postfix_virtual_hosting">http://www.howtoforge.com/linux_postfix_virtual_hosting</a><br />
<a href="http://www.howtoforge.com/linux_postfix_virtual_hosting_2">http://www.howtoforge.com/linux_postfix_virtual_hosting_2</a></p>
<p><em>If this information was useful, please leave a comment to let me know!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nikrivers.com/linksys-nslu2/email-with-postfix-and-dovecot/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
