{"id":1947,"date":"2013-02-10T20:56:23","date_gmt":"2013-02-10T18:54:57","guid":{"rendered":"http:\/\/tom.scholten.nu\/weblog\/?page_id=1947"},"modified":"2013-02-16T22:14:33","modified_gmt":"2013-02-16T20:14:33","slug":"postfix_mysql_howto","status":"publish","type":"page","link":"https:\/\/tom.scholten.nu\/weblog\/postfix_mysql_howto","title":{"rendered":"Postfix MySQL howto v1.0"},"content":{"rendered":"<p>Last updated Februari 10 2013<\/p>\n<h2>Full-fledged Postfix using MySQL HOWTO<\/h2>\n<h3>Postfix, MySQL, IMAP, WebMail, Virus- and spamscanning\/checking mail system<\/h3>\n<h4>by Tom Scholten and authors of likewise documents<\/h4>\n<h3>v1.0<\/h3>\n<h4>Special thanks to Remco from WellnessAndConsultancy for testdriving this tutorial<\/h4>\n<table width=\"100%\" border=\"0\">\n<tbody>\n<tr>\n<td align=\"left\"><img loading=\"lazy\" decoding=\"async\" title=\"Postfix\" alt=\"Postfix\" src=\"http:\/\/tom.scholten.nu\/weblog\/wp-content\/uploads\/2007\/03\/postfix1.gif\" width=\"130\" height=\"91\" align=\"middle\" \/><\/td>\n<td align=\"right\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1954\" alt=\"logo_250x80\" src=\"http:\/\/tom.scholten.nu\/weblog\/wp-content\/uploads\/2013\/02\/logo_250x80.jpg\" width=\"250\" height=\"80\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>As my\u00c2\u00a0<a href=\"http:\/\/tom.scholten.nu\/weblog\/postfix_ldap_howto\">PostfixLDAP howto<\/a> is getting agy and less used with a request from a fellow web-company and one of the main <a href=\"http:\/\/www.compa.nl\">CT<\/a> customers I&#8217;ve decided to write down a comprehensive guide on how to install a mailserver using Postfix based on MySQL &#8211; obviously with all the things I think you&#8217;ll need with that!<\/p>\n<p>This howto will \u00c2\u00a0&#8211; if succesfully deployed &#8211; give you an (FreeBSD) Postfix MySQL ViMbAdmin setup with Dovecot, RoundCube and MailScanner. Say what?<\/p>\n<ul>\n<li><span style=\"line-height: 13px;\"><a href=\"http:\/\/www.postfix.org\">Postfix<\/a>; main mailserver (as in SMTP, so for server traffic and sending mail)<\/span><\/li>\n<li><a href=\"http:\/\/www.mysql.org\">MySQL<\/a>; database<\/li>\n<li><a href=\"http:\/\/www.opensolutions.ie\/vimbadmin\">ViMbAdmin<\/a>; web-gui to administer (or give someone partial rights) your mail-addresses<\/li>\n<li><a href=\"http:\/\/www.dovecot.org\">Dovecot<\/a>; main mailserver (as in POP\/IMAP, for fetching, storing your mail) including SIEVE (through pigeonhole) to have customer rule processing<\/li>\n<li><a href=\"http:\/\/roundcube.net\">RoundCube<\/a>; webmail frontend<\/li>\n<li><a href=\"http:\/\/mailscanner.info\">MailScanner<\/a> + <a href=\"http:\/\/mailwatch.sf.net\">MailWatch<\/a>; virus and spam-checks, the MailWatch is a front-end to which you can also have people de-quarantine their mail<\/li>\n<\/ul>\n<p><b>Rules of engagement<\/b><\/p>\n<p>This only describes how to build a mail-host on a secure, trusted, local network. We are not dealing with some of the things you should have in place first<\/p>\n<ul>\n<li><b><\/b>working and active pf.conf<\/li>\n<li><b><\/b>ssl-certificates for your web- and mail servers<\/li>\n<li><b><\/b>(note that you DO need the \u00e2\u20ac\u02dcpem\u00e2\u20ac\u2122 format for the mailservers in this document, revert to google and \u00e2\u20ac\u02dccacert mailserver pem\u00e2\u20ac\u2122 for more information<\/li>\n<li>ensure your apache webserver has the certificates (or test-certificates) working and the production php.ini applied (see \/usr\/local\/etc\/php.ini-production)<\/li>\n<\/ul>\n<p><span style=\"color: #ff0000;\">We do not take any responsibility for your setup &#8211; this howto serves as a recipe on how you could do it. Read it and interpret it but create your own <strong>secure<\/strong> solution!<\/span><\/p>\n<p><b>Documentation sources<\/b><\/p>\n<blockquote>\n<ul>\n<li><a href=\"https:\/\/github.com\/opensolutions\/ViMbAdmin\/wiki\/ \">https:\/\/github.com\/opensolutions\/ViMbAdmin\/wiki\/<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/opensolutions\/ViMbAdmin\/wiki\/ \">http:\/\/wiki.dovecot.org\/HowTo\/DovecotLDAPostfixAdminMySQL<\/a><\/li>\n<li><a href=\"http:\/\/mailscanner.info\/postfix.html\">http:\/\/mailscanner.info\/postfix.html<\/a><\/li>\n<li><a href=\"http:\/\/trac.roundcube.net\/wiki\/Howto_Install\">http:\/\/trac.roundcube.net\/wiki\/Howto_Install<\/a><\/li>\n<\/ul>\n<\/blockquote>\n<p><b>FreeBSD 9.1 base install<\/b><\/p>\n<p>install \u00e2\u20ac\u02dcplain\u00e2\u20ac\u2122 (no lib32\/games\/doc) with ports<br \/>\n<span style=\"color: #3366ff;\"><i># freebsd-update fetch<br \/>\n<\/i><i># portsnap fetch<br \/>\n<\/i><i># cd \/usr\/ports\/ports-mgmt\/portmaster<br \/>\n<\/i><i># make install<\/i><\/span><\/p>\n<p>Add to \/etc\/rc.conf<\/p>\n<p><span style=\"color: #339966;\"><em>sendmail_enable=&#8221;NO&#8221;<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> sendmail_submit_enable=&#8221;NO&#8221;<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> sendmail_outbound_enable=&#8221;NO&#8221;<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> sendmail_msp_queue_enable=&#8221;NO&#8221;<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> mysql_enable=&#8221;YES&#8221;<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> apache22_enable=&#8221;YES&#8221;<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> postfix_enable=&#8221;YES&#8221;<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> dovecot_enable=&#8221;YES&#8221;<\/em><\/span><\/p>\n<p>Edit \/etc\/make.conf<br \/>\n<span style=\"color: #339966;\"><em>WITHOUT_X11=yes<\/em><\/span><\/p>\n<p><strong>Prepare ports<\/strong><\/p>\n<p>Fetch the below \/var\/db\/ports contents<br \/>\n<a href=\"http:\/\/www.compa.nl\/tmp\/mailserver.ports.tgz  \">http:\/\/www.compa.nl\/tmp\/mailserver.ports.tgz<\/a><\/p>\n<p><strong>Build the following<\/strong><\/p>\n<p><span style=\"color: #3366ff;\"><em># portmaster mail\/postfix databases\/mysql55-server mail\/roundcube mail\/dovecot2 mail\/dovecot2-pigeonhole www\/apache22 lang\/php5 lang\/php5-extensions devel\/git devel\/subversion www\/smarty3 www\/zend-framework databases\/pear-Doctrine12 ftp\/wget shells\/bash mail\/mailscanner databases\/p5-DBD-mysql<\/em><\/span><\/p>\n<p>Note; do <strong>not<\/strong> build MailScanner with <em><span style=\"color: #339966;\">bdc<\/span><\/em>!<\/p>\n<p><strong>Prepare database environment<\/strong><br \/>\n<em><span style=\"color: #3366ff;\"># mysql -uroot<\/span><\/em><\/p>\n<p><em><span style=\"color: #339966;\">&gt; use mysql;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; update user SET password=password(\u00e2\u20ac\u02dcmastersecret0\u00e2\u20ac\u2122) where user=\u00e2\u20ac\u02dcroot\u00e2\u20ac\u2122;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; flush privileges;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; quit;<\/span><\/em><\/p>\n<p><em><span style=\"color: #3366ff;\"># mysql -uroot -p<\/span><\/em><\/p>\n<p><em><span style=\"color: #339966;\">&gt; create database webmail;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; grant ALL ON webmail.* to \u00e2\u20ac\u02dcroundcube\u00e2\u20ac\u2122@localhost IDENTIFIED by \u00e2\u20ac\u02dcsecret0\u00e2\u20ac\u2122;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; create database mailscanner;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; grant ALL ON mailscanner.* to \u00e2\u20ac\u02dcmailwatch\u00e2\u20ac\u2122@localhost IDENTIFIED by \u00e2\u20ac\u02dcsecrety\u00e2\u20ac\u2122;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; grant file on *.* to mailwatch@localhost identified by \u00e2\u20ac\u02dcsecrety\u00e2\u20ac\u2122;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; create database postfixmail;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; grant ALL ON postfixmail.* to \u00e2\u20ac\u02dcvimbadmin\u00e2\u20ac\u2122@localhost IDENTIFIED by \u00e2\u20ac\u02dcsecret1\u00e2\u20ac\u2122;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; grant SELECT ON postfixmail.* to &#8216;dovecot&#8217;@&#8217;localhost&#8217; IDENTIFIED by &#8216;secret2&#8217;;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; grant SELECT ON postfixmail.* to &#8216;postfix&#8217;@&#8217;localhost&#8217; IDENTIFIED by &#8216;secret3&#8217;;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; grant SELECT, RELOAD, LOCK TABLES ON *.* to &#8216;backup&#8217;@&#8217;localhost&#8217; IDENTIFIED by &#8216;secret4&#8217;;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; flush privileges;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; quit;<\/span><\/em><\/p>\n<p><em><span style=\"color: #3366ff;\"># mkdir -p \/home\/vmail<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># chmod 770 \/home\/vmail<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># vi \/etc\/group<\/span><\/em><br \/>\n<span style=\"color: #000000;\">Add a group \u00e2\u20ac\u02dcvmail\u00e2\u20ac\u2122 with id 2000<\/span><br \/>\n<em><span style=\"color: #3366ff;\"># useradd<\/span><\/em><\/p>\n<p><em><span style=\"color: #339966;\">&gt; \u00e2\u20ac\u0153vmail\u00e2\u20ac\u009d as username<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> &gt; \u00e2\u20ac\u0153Virtual Mailbox\u00e2\u20ac\u009d as description<br \/>\n&gt; id 2000<br \/>\n<\/span><\/em><em><span style=\"color: #339966;\">&gt; \/home\/vmail as directory<br \/>\n<\/span><\/em><em><span style=\"color: #339966;\">&gt; group = vmail<br \/>\n<\/span><\/em><em id=\"__mceDel\"><em id=\"__mceDel\"><em><span style=\"color: #339966;\">&gt; additional groups = mail<br \/>\n<\/span><\/em><\/em><\/em><em id=\"__mceDel\"><em id=\"__mceDel\"><em id=\"__mceDel\"><em><span style=\"color: #339966;\">&gt; nologin<\/span><\/em><\/em><\/em><\/em><\/p>\n<p><em><span style=\"color: #3366ff;\"># chown -R vmail:mail \/home\/vmail<\/span><\/em><\/p>\n<p><strong>Dovecot:<\/strong><\/p>\n<p><span style=\"color: #3366ff;\"># cp -pfr \/usr\/local\/share\/doc\/dovecot\/example-configs\/* \/usr\/local\/etc\/dovecot\/<\/span><\/p>\n<p>Adjust according to<br \/>\n<a href=\"http:\/\/www.compa.nl\/tmp\/mailserver.dovecott.diff.txt  \">http:\/\/www.compa.nl\/tmp\/mailserver.dovecott.diff.txt<\/a><\/p>\n<p><strong>Postfix:<\/strong><\/p>\n<p>Add to \/usr\/local\/etc\/postfix\/master.cf<br \/>\n<span style=\"color: #339966;\"><em># Dovecot LDA<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> dovecot unix &#8211; n n &#8211; &#8211; pipe<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> flags=DRhu user=vmail:mail argv=\/usr\/local\/libexec\/dovecot\/deliver -d ${recipient}<\/em><\/span><\/p>\n<p>Add the contents of <a href=\"http:\/\/www.compa.nl\/tmp\/mailserver.postfix.main.cf.add.txt\">http:\/\/www.compa.nl\/tmp\/mailserver.postfix.main.cf.add.txt<\/a>\u00c2\u00a0to main.cf<\/p>\n<p>Create the mysql_ files as shown in <a href=\"http:\/\/www.compa.nl\/mailserver.postfix.mysql.files.txt\">http:\/\/www.compa.nl\/mailserver.postfix.mysql.files.txt<\/a><\/p>\n<p>Add <span style=\"color: #339966;\">header_checks = regexp:\/usr\/local\/etc\/postfix\/header_checks<\/span> to main.cf<br \/>\nCreate the file and have it contain<br \/>\n<em><span style=\"color: #339966;\">\/^Received:\/ HOLD<\/span><\/em><\/p>\n<p><strong>Apache:<\/strong><\/p>\n<p>In \/usr\/local\/etc\/apache22\/httpd.conf<\/p>\n<ul>\n<li>Find the \u00e2\u20ac\u02dcDirectoryIndex\u00e2\u20ac\u2122 declaration and add \u00e2\u20ac\u02dcindex.php\u00e2\u20ac\u2122 behind index.html (with a space separating them)<\/li>\n<li>\u00e2\u20ac\u02dcuntick\u00e2\u20ac\u2122 the \u00e2\u20ac\u02dcvhost\u00e2\u20ac\u2122 file inclusion near the bottom<\/li>\n<li>add the following somewhere near there<\/li>\n<\/ul>\n<p><em><span style=\"color: #339966;\"># PHP settings<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\">Include etc\/apache22\/extra\/httpd-php.conf<\/span><\/em><\/p>\n<p>Create an .\/extra\/httpd-php.conf containing<br \/>\n<span style=\"color: #339966;\"><em>#<\/em><\/span><br \/>\n<span style=\"color: #339966;\"><em> # This is the Apache server configuration file providing PHP support.<\/em><\/span><br \/>\n<em style=\"color: #339966;\">AddType application\/x-httpd-php .php<br \/>\n<\/em><span style=\"color: #339966;\"><em>AddType application\/x-httpd-php-source .phps<\/em><\/span><\/p>\n<p>Create a file in .\/Includes named \u00e2\u20ac\u02dcyourhost.conf\u00e2\u20ac\u2122<br \/>\n<em><span style=\"color: #339966;\">&lt;Virtualhost *:80&gt;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> ServerName yourhost.example.com<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> DocumentRoot \/usr\/local\/www\/apache22\/data\/<br \/>\n<\/span><\/em><em><span style=\"color: #339966;\">Alias \/vimbadmin \/usr\/local\/vimbadmin\/public<\/span><\/em><\/p>\n<p><em><span style=\"color: #339966;\">&lt;Directory \/usr\/local\/vimbadmin\/public&gt;<\/span><\/em><\/p>\n<p><em><span style=\"color: #339966;\">Options FollowSymLinks<br \/>\n<\/span><\/em><em><span style=\"color: #339966;\">AllowOverride None<br \/>\n<\/span><\/em><em><span style=\"color: #339966;\">Order allow,deny<br \/>\n<\/span><\/em><em><span style=\"color: #339966;\">allow from all<br \/>\n<\/span><\/em><em><span style=\"color: #339966;\">SetEnv APPLICATION_ENV production<\/span><\/em><\/p>\n<p><em><span style=\"color: #339966;\">RewriteEngine On<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> RewriteCond %{REQUEST_FILENAME} -s [OR]<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> RewriteCond %{REQUEST_FILENAME} -l [OR]<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> RewriteCond %{REQUEST_FILENAME} -d<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> RewriteRule ^.*$ &#8211; [NC,L]<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> RewriteRule ^.*$ \/vimbadmin\/index.php [NC,L]<br \/>\n<\/span><\/em><em><span style=\"color: #339966;\">&lt;\/Directory&gt;<br \/>\n<\/span><\/em><em id=\"__mceDel\"><em id=\"__mceDel\"><em><span style=\"color: #339966;\">&lt;\/VirtualHost&gt;<\/span><\/em><\/em><\/em><\/p>\n<p><strong>Vimbadmin<\/strong><br \/>\n<em><span style=\"color: #3366ff;\"># cd \/usr\/local\/<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># wget {url to latest version from https:\/\/github.com\/opensolutions\/ViMbAdmin\/archives\/develop}<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># tar xfvz {file you got}<\/span><\/em><\/p>\n<p><em><span style=\"color: #3366ff;\"># ln -s {dir it created} vimbadmin<\/span><\/em><\/p>\n<p><em><span style=\"color: #3366ff;\"># cd \/usr\/local\/vimbadmin<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># cp application\/configs\/application.ini.dist application\/configs\/application.ini<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># vi application\/configs\/application.ini<\/span><\/em><\/p>\n<p>Set <span style=\"color: #339966;\"><em>resources.frontController.params.displayExceptions = 0<\/em><\/span> to 1<br \/>\nAdjust ID\u00e2\u20ac\u2122s to 2000<br \/>\nAdjust connection to<br \/>\n<em><span style=\"color: #339966;\">resources.doctrine.connection_string = &#8220;mysql:\/\/vimbadmin:supersecret@localhost\/postfixmail&#8221;<\/span><\/em><\/p>\n<p><span style=\"color: #ff0000;\"><strong>DO NOT FORGET TO RESET displayExceptions back to 0 if vimbadmin GUI works!<\/strong><\/span><\/p>\n<p>Next switch to the \/usr\/local\/vimbadmin\/library directory and create symlinks<br \/>\n<span style=\"color: #3366ff;\"><em># ln -s \/usr\/local\/share\/pear\/Doctrine Doctrine<\/em><\/span><br \/>\n<span style=\"color: #3366ff;\"><em># ln -s \/usr\/local\/share\/smarty3\/ Smarty<\/em><\/span><br \/>\n<span style=\"color: #3366ff;\"><em># ln -s \/usr\/local\/share\/ZendFramework\/library\/Zend Zend<\/em><\/span><\/p>\n<p>Now initialize the vimbadmin database<br \/>\n<em><span style=\"color: #3366ff;\"># cd \/usr\/local\/vimbadmin<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># bin\/doctrine-cli.php create-tables<\/span><\/em><\/p>\n<p><strong>Putting it together<\/strong><\/p>\n<p><strong>Stage1<\/strong><br \/>\nStart your webserver<br \/>\n<span style=\"color: #3366ff;\"><em># \/usr\/local\/etc\/rc.d\/apache22 start<\/em><\/span><\/p>\n<p>Browse to <span style=\"color: #339966;\">http:\/\/192.168.0.1\/vimbadmin<\/span><\/p>\n<p>Get the \u00e2\u20ac\u0153salt\u00e2\u20ac\u009d from this page<\/p>\n<p>Put that in the application.ini file mentioned above + reset the displayExceptions to 0<\/p>\n<p>Reload the page<br \/>\nPut in the salt<br \/>\nPut in a mailaddress en password<\/p>\n<p>Congratulations, you can now login again \ud83d\ude42<\/p>\n<p>Now create a test-domain (example.org) + mailbox (tester@example.org)<\/p>\n<p><strong>Stage2<\/strong><br \/>\nInitiate a tail (-f) on \/var\/log\/maillog<br \/>\n<span style=\"color: #3366ff;\"><em># \/usr\/local\/etc\/rc.d\/dovecot start<\/em><\/span><\/p>\n<p>Look for any errors and correct them (did you do your certificates!)<\/p>\n<p>Check postfix config (warnings are OK-ish for now)<br \/>\n<em><span style=\"color: #3366ff;\"># postfix check<\/span><\/em><br \/>\n<span style=\"color: #000000;\"> If all is well start postfix<\/span><br \/>\n<em><span style=\"color: #3366ff;\"># \/usr\/local\/etc\/rc.d\/postfix start<\/span><\/em><\/p>\n<p>Again, same thing (warnings are OK-ish for now)<\/p>\n<p>Check resolving<\/p>\n<p><em><span style=\"color: #3366ff;\"># postmap -q testuser@example.org mysql:\/usr\/local\/etc\/postfix\/mysql_virtual_mailbox_maps.cf<\/span><\/em><\/p>\n<p>Then start a telnet session to verify delivery<\/p>\n<p><span style=\"color: #3366ff;\"><em>$ telnet localhost 25<\/em><\/span><\/p>\n<p><span style=\"color: #339966;\">you&gt; ehlo host<\/span><br \/>\n250-something<br \/>\n<span style=\"color: #339966;\">you&gt; mail from: johndoe<\/span><br \/>\n250 2.1.0 Ok<br \/>\n<span style=\"color: #339966;\">you&gt; rcpt to: johndoe<\/span><br \/>\nTHIS ONE SHOULD FAIL<br \/>\n<span style=\"color: #339966;\">you&gt; rcpt to: johndoe@example.org<\/span><br \/>\nTHIS ONE SHOULD FAIL<br \/>\n<span style=\"color: #339966;\">you&gt; rcpt to: testuser@example.org<\/span><br \/>\nTHIS ONE SHOULD GO OK<br \/>\n250 2.1.5 Ok<br \/>\n<span style=\"color: #339966;\">you&gt; data<\/span><br \/>\n354 End data with .<br \/>\n<span style=\"color: #339966;\">you&gt; test<\/span><br \/>\n<span style=\"color: #339966;\">you&gt; .<\/span><br \/>\n250 2.0.0 Ok: queued as 9729067C17<br \/>\n<span style=\"color: #339966;\">you&gt; quit<\/span><br \/>\n221 2.0.0 Bye<br \/>\nConnection closed by foreign host.<\/p>\n<p>Check your postfix\/dovecot output in maillog for delivery<\/p>\n<p><em><span style=\"color: #3366ff;\"># ls -lR \/home\/mail\/example.org<\/span><\/em><\/p>\n<p>There should be some mail in the maildir there \ud83d\ude42<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Congratulations you now have a working, basic, setup for your mailserver<\/strong><\/span><\/p>\n<p><strong>Next up<\/strong><\/p>\n<p>Apache config for PHP<br \/>\n<em><span style=\"color: #3366ff;\"># cp \/usr\/local\/etc\/php.ini-production \/usr\/local\/etc\/php.ini<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># vi \/usr\/local\/etc\/php.ini<\/span><\/em><br \/>\nadjust error_log to \/var\/log\/php.log<br \/>\nadjust date.timezone to \u00e2\u20ac\u02dcCET\u00e2\u20ac\u2122<br \/>\n<em><span style=\"color: #3366ff;\"># touch \/var\/log\/php.log<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># chown www:www \/var\/log\/php.log<\/span><\/em><br \/>\nAdd php.log to \/etc\/newsyslog<br \/>\nRestart apache \/usr\/local\/etc\/rc.d\/apache22 restart<\/p>\n<p><strong>MailScanner (and Postfix)<\/strong><\/p>\n<p>In \/usr\/local\/etc\/postfix add <span style=\"color: #339966;\">header_checks = regexp:\/usr\/local\/etc\/postfix\/header_checks<\/span> to main.cf<br \/>\nCreate the file <span style=\"color: #339966;\">header_checks<\/span> and have it contain<br \/>\n<span style=\"color: #339966;\"><em>\/^Received:\/ HOLD<\/em><\/span><\/p>\n<p>Next create Mailscanners\u00e2\u20ac\u2122 directories<br \/>\n<em><span style=\"color: #3366ff;\"># mkdir -p \/var\/spool\/MailScanner\/incoming<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># mkdir -p \/var\/spool\/MailScanner\/incoming\/Locks<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># mkdir -p \/var\/spool\/MailScanner\/quarantine<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># mkdir -p \/var\/spool\/mqueue<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># mkdir -p \/var\/spool\/mqueue.in<\/span><\/em><\/p>\n<p>Getting \u00e2\u20ac\u02dcmailwatch\u00e2\u20ac\u2122 from http:\/\/sourceforge.net\/projects\/mailwatch\/files\/<br \/>\n<em><span style=\"color: #3366ff;\"># mkdir \/tmp\/src<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># cd \/tmp\/src<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># wget {url}<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># tar xfvz {file from url}<\/span><\/em><br \/>\n<em><span style=\"color: #3366ff;\"># cd mailw*<\/span><\/em><\/p>\n<p><span style=\"color: #ff6600;\">*<strong>HINT<\/strong>* if the below command fails, replace \u00e2\u20ac\u0153TYPE=MyISAM\u00e2\u20ac\u009d with \u00e2\u20ac\u0153Engine=MyISAM\u00e2\u20ac\u009d through the create file and look for \u00e2\u20ac\u0153timestamp(14)\u00e2\u20ac\u009d and set this to \u00e2\u20ac\u0153timestamp\u00e2\u20ac\u009d<\/span><br \/>\n<em><span style=\"color: #3366ff;\">#mysql -umailwatch -p mailscanner &lt; create.sql<\/span><\/em><br \/>\n<em id=\"__mceDel\"><span style=\"color: #3366ff;\"><br \/>\n#vi MailScanner_perl_scripts\/MailWatch.pm<\/span><br \/>\n<\/em><em id=\"__mceDel\"><br \/>\n<\/em>Edit the file for your database connections<em id=\"__mceDel\"><br \/>\n<span style=\"color: #3366ff;\"># cp MailScanner_perl_scripts\/MailWatch.pm \/usr\/local\/lib\/MailScanner\/MailScanner\/CustomFunctions\/<\/span><br \/>\n<\/em>Create the admin user<em id=\"__mceDel\"><br \/>\n<span style=\"color: #3366ff;\">#mysql mailscanner -u mailwatch -p<\/span><br \/>\n<span style=\"color: #339966;\">&gt; INSERT INTO users SET username = &#8216;youruser&#8217;, password = md5(&#8216;secret2much&#8217;), fullname = &#8216;Me Myself and I&#8217;, type =&#8217;A&#8217;<br \/>\n<\/span><\/em><span style=\"color: #339966;\"><em id=\"__mceDel\"><em id=\"__mceDel\">&gt; \\q<\/em><\/em><\/span><\/p>\n<p><em id=\"__mceDel\"><em id=\"__mceDel\"><span style=\"color: #3366ff;\"># mkdir {\/wwwroot}\/mailwatch<\/span><br \/>\n<span style=\"color: #3366ff;\"># cp -pfr mailscanner\/* {\/wwwroot}\/mailwatch\/<\/span><br \/>\n<span style=\"color: #3366ff;\"># cp {\/wwwroot}\/mailwatch\/conf.php.example {\/wwwroot}\/mailwatch\/conf.php<\/span><br \/>\n<span style=\"color: #3366ff;\"># vi {\/wwwroot}\/mailwatch\/conf.php<\/span><br \/>\n<\/em><\/em>Set your DB-user and Password &amp; change below lines<em id=\"__mceDel\"><em id=\"__mceDel\"><br \/>\n<span style=\"color: #339966;\">define(&#8216;MAILWATCH_HOME&#8217;, &#8216;{\/wwwroot}\/mailwatch&#8217;);<\/span><br \/>\n<span style=\"color: #339966;\"> define(&#8216;MS_CONFIG_DIR&#8217;, &#8216;\/usr\/local\/etc\/MailScanner\/&#8217;);<\/span><br \/>\n<span style=\"color: #339966;\"> define(&#8216;MS_LIB_DIR&#8217;, &#8216;\/usr\/local\/lib\/MailScanner\/&#8217;);<\/span><br \/>\n<span style=\"color: #339966;\"> define(&#8216;SA_RULES_DIR&#8217;, &#8216;\/usr\/local\/share\/spamassassin\/&#8217;);<\/span><\/em><\/em><\/p>\n<p>Edit \/usr\/local\/etc\/MailScanner\/MailScanner.conf<br \/>\nChange<\/p>\n<ul>\n<li><span style=\"color: #339966;\">Always Looked Up Last = &amp;MailWatchLogging<\/span><\/li>\n<li><span style=\"color: #339966;\">Detailed Spam Report = yes<\/span><\/li>\n<li><span style=\"color: #339966;\">Quarantine Whole Message = yes<\/span><\/li>\n<li><span style=\"color: #339966;\">Quarantine Whole Message As Queue Files = no<\/span><\/li>\n<li><span style=\"color: #339966;\">Include Scores In SpamAssassin Report = yes<\/span><\/li>\n<li><span style=\"color: #339966;\">Quarantine User = root<\/span><\/li>\n<li><span style=\"color: #339966;\">Quarantine Group = apache (this should be the same group as your web server)<\/span><\/li>\n<li><span style=\"color: #339966;\">Quarantine Permissions = 0660<\/span><\/li>\n<li><span style=\"color: #339966;\">Incoming Work Permissions = 0640<\/span><\/li>\n<\/ul>\n<p>Clean up<br \/>\n<em><span style=\"color: #3366ff;\"># rm -r \/tmp\/src\/mailwatch*<\/span><\/em><\/p>\n<p>Set groups<br \/>\n<em><span style=\"color: #3366ff;\"># vi \/etc\/group<br \/>\n<\/span><span style=\"color: #339966;\">Add &#8220;clamav&#8221; to the postfix group<\/span><\/em><\/p>\n<p>Now add to your \/etc\/rc.conf<\/p>\n<p><em><span style=\"color: #339966;\">mailscanner_enable=\u00e2\u20ac\u009dyes\u00e2\u20ac\u009d<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> clamav_clamd_enable=&#8221;YES&#8221;<\/span><\/em><br \/>\n<em><span style=\"color: #339966;\"> clamav_freshclam_enable=&#8221;YES&#8221;<\/span><\/em><\/p>\n<p><em><span style=\"color: #3366ff;\"># \/usr\/local\/etc\/rc.d\/clamav-freshclam start<\/span><\/em><br \/>\n{wait for a bit}<br \/>\n<span style=\"color: #3366ff;\"><em># \/usr\/local\/etc\/rc.d\/clamav-clamd start<\/em><\/span><br \/>\n{make sure it\u00e2\u20ac\u2122s succesfull, or wait some more and retry}<br \/>\n{If taking too long, run \u00e2\u20ac\u02dc<span style=\"color: #3366ff;\"><em>freshclam<\/em><\/span>\u00e2\u20ac\u2122 and wait for it to download}<br \/>\n<em><span style=\"color: #3366ff;\"># \/usr\/local\/etc\/rc.d\/mailscanner start<\/span><\/em><br \/>\nWatch for the output and try sending out a testmail to root &#8211; see if logging and processing work again<\/p>\n<p>Add the following lines to your apache configuration, we&#8217;ve included the rules for vimbadmin just to be sure \ud83d\ude42<\/p>\n<pre><span style=\"color: #339966;\"><em>&lt;Virtualhost *:80&gt;\r\n  ServerName newmail.example.org\r\n  DocumentRoot \/usr\/local\/www\/apache22\/data\/\r\n  Alias \/vimbadmin \/usr\/local\/vimbadmin\/public\r\n  &lt;Directory \/usr\/local\/vimbadmin\/public&gt;\r\n    Options FollowSymLinks\r\n    AllowOverride None\r\n    Order allow,deny\r\n    allow from all\r\n<\/em><\/span>\r\n<span style=\"color: #339966;\"><em>    SetEnv APPLICATION_ENV production\r\n<\/em><\/span>\r\n<span style=\"color: #339966;\"><em>    RewriteEngine On\r\n    RewriteCond %{REQUEST_FILENAME} -s [OR]\r\n    RewriteCond %{REQUEST_FILENAME} -l [OR]\r\n    RewriteCond %{REQUEST_FILENAME} -d\r\n    RewriteRule ^.*$ - [NC,L]\r\n    RewriteRule ^.*$ \/vimbadmin\/index.php [NC,L]\r\n  &lt;\/Directory&gt;\r\n\r\n  Alias \/mailscanner \/www\/example.org\/newmail\/secure\/mailwatch\r\n  &lt;Directory \/www\/example.org\/newmail\/secure\/mailwatch&gt;\r\n    Options FollowSymLinks\r\n    AllowOverride None\r\n    Order allow,deny\r\n    allow from all\r\n\r\n  SetEnv APPLICATION_ENV production\r\n\r\n  &lt;\/Directory&gt;\r\n&lt;\/VirtualHost&gt;\r\n<\/em><\/span><\/pre>\n<p><strong>Todo:<\/strong><\/p>\n<p>Roundcube config<\/p>\n<p><strong>Before going live<\/strong><\/p>\n<p>Check firewall (pf.conf), and it\u00e2\u20ac\u2122s activation<br \/>\nInstall tripwire, monitoring and all that kind of stuff!<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/tom.scholten.nu\">Tom Scholten<\/a>\u00c2\u00a0is consultant with\u00c2\u00a0<a href=\"http:\/\/snow.nl\">Snow B.V.<\/a>, a Dutch Technical Consultancy Company supplying specialists in the fields of Storage, Networking and Unix<\/p>\n<table width=\"100%\" border=\"0\">\n<tbody>\n<tr>\n<td align=\"left\"><a href=\"http:\/\/www.snow.nl\"><img loading=\"lazy\" decoding=\"async\" title=\"Snow B.V.\" alt=\"Snow B.V.\" src=\"http:\/\/tom.scholten.nu\/weblog\/wp-content\/uploads\/2007\/03\/snow-logo1.jpg\" width=\"200\" height=\"67\" align=\"left\" \/><\/a><\/td>\n<td align=\"left\"><\/td>\n<td align=\"right\"><\/td>\n<td align=\"right\"><a href=\"http:\/\/www.freebsd.org\"><img loading=\"lazy\" decoding=\"async\" title=\"FreeBSD\" alt=\"FreeBSD\" src=\"http:\/\/tom.scholten.nu\/weblog\/wp-content\/uploads\/2007\/03\/fbsd-full1.png\" width=\"200\" height=\"72\" align=\"right\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Last updated Februari 10 2013 Full-fledged Postfix using MySQL HOWTO Postfix, MySQL, IMAP, WebMail, Virus- and spamscanning\/checking mail system by Tom Scholten and authors of<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-1947","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/tom.scholten.nu\/weblog\/wp-json\/wp\/v2\/pages\/1947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tom.scholten.nu\/weblog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tom.scholten.nu\/weblog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tom.scholten.nu\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tom.scholten.nu\/weblog\/wp-json\/wp\/v2\/comments?post=1947"}],"version-history":[{"count":6,"href":"https:\/\/tom.scholten.nu\/weblog\/wp-json\/wp\/v2\/pages\/1947\/revisions"}],"predecessor-version":[{"id":1955,"href":"https:\/\/tom.scholten.nu\/weblog\/wp-json\/wp\/v2\/pages\/1947\/revisions\/1955"}],"wp:attachment":[{"href":"https:\/\/tom.scholten.nu\/weblog\/wp-json\/wp\/v2\/media?parent=1947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}