<?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>/dev/null &#187; DBMail</title>
	<atom:link href="http://www.nulldevice.de/tag/dbmail/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nulldevice.de</link>
	<description>Static is evil.</description>
	<lastBuildDate>Fri, 18 Nov 2011 17:28:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Exporting users from DBMail to Postfix lookup table</title>
		<link>http://www.nulldevice.de/2008/05/exporting-users-from-dbmail-to-postfix-lookup-table/</link>
		<comments>http://www.nulldevice.de/2008/05/exporting-users-from-dbmail-to-postfix-lookup-table/#comments</comments>
		<pubDate>Sun, 11 May 2008 13:25:11 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[DBMail]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Postfix]]></category>
		<category><![CDATA[Email]]></category>

		<guid isPermaLink="false">http://www.nulldevice.de/?p=801</guid>
		<description><![CDATA[I wrote so many scripts the last couple of years that I can&#8217;t remember anymore&#8230; anyways, I was working on my mail server config today and found this little PHP script that exports users from the DBMail database to a Postfix lookup table, so that unknown users can be rejected upfront by postfix (thus reducing [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote so many scripts the last couple of years that I can&#8217;t remember anymore&#8230; anyways, I was working on my mail server config today and found this little PHP script that exports users from the DBMail database to a <strong>Postfix lookup table</strong>, so that unknown users can be rejected upfront by postfix (thus reducing the load on the mail server). It also outputs a list of domains.</p>
<pre>#!/usr/local/bin/php
&lt;?php
$mysqli = new mysqli("localhost", "dbmail", "yourpassword", "dbmail");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$q = $mysqli-&gt;query("SELECT DISTINCT alias FROM dbmail_aliases");
$content = '';
$domains = array();
while($r=$q-&gt;fetch_assoc()) {
$content .= $r['alias']." OK\n";
$parts = explode('@', $r['alias']);
if(!in_array($parts[1], $domains)) {
$domains[] = $parts[1];
}
}
file_put_contents('myusers', $content);
file_put_contents('mydomains', join("\n", $domains));
exec('postmap myusers');
$mysqli-&gt;close();
?&gt;</pre>
<p>Maybe it is of some use for anybody out there&#8230; the config in <tt>/etc/postfix/main.cf</tt> should look like:</p>
<pre>mydestination = /etc/postfix/mydomains localhost
local_recipient_maps = hash:/etc/postfix/myusers $alias_maps</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nulldevice.de/2008/05/exporting-users-from-dbmail-to-postfix-lookup-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

