If you need a mail system, chances are that you’re going to need an SMTP server to receive and send emails, a POP3 or IMAP server to have them downloaded by the client, a webmail to check them while you’re out of office and, of course, an antivirus. This guide will help you set up such a system using: - FreeBSD: no words to spend on it. Simply the best freely available operating system. Jump to http://www.freebsd.org and get it! To have all it up and running you need an installed FreeBSD system, I’ll assume you’re using 6.2. You must have installed the apache http server, any version over and including 1.3 will be ok as long as you have PHP installed. It is beyond the scope of this document how to install it, but in the majority of the cases you may use the standard pkg_add method. Also, installing Postifixadmin or squirrelmail via package will also install apache and php as a dependency. If you will be building your packages, then remember to update the ports collection. Finally you need MySql (I’m using 5.x). When you install postfix and dovecot, remember to compile with MySql extensions. Let’s start. The difficult in setting up such a server resides in matching the parameters in the different configuration files for the different programs. Let’s start installing Dovecot and then Postfix. cd /usr/ports/mail/dovecot Checking the MySQL support. Then: cd /usr/ports/mail/postfix and select This will download and compile postfix and dovecot. Then add this to your rc.conf. sendmail_enable="NO" Then we need to get the uid of user postfix: # id postfix So mine is 125, your may vary. Take note of this number as we’ll need it later. Let’s install postfixadmin: /usr/ports/mail/postfixadmin And go with standard options. You’ll get some php5 dependencies. Now let’s configure Apache. I prefer having a single virtual host for any site, so ee /usr/local/etc/apache2/httpd.conf Jump to the endings of the file and uncomment NameVirtualHost *:80 Then create a virtual host for your Postfixadmin. Go to /usr/local/www/postfixadmin and edit DATABASE_MYSQL.TXT to change the password in the first lines. Then mysql <DATABASE_MYSQL.TXT to create the database. Then edit config.inc.php in the postfixadmin folder and set: - database_password to the password you changed in DATABASE_MYSQL.TXT If you want to limit local access to postfixadmin dir do: chown -R www:www postfixadmin/ Now try to access your site using your servername (remember we’re using name based virtual hosting). You should see all OKs. If it is as expected, delete setup.php and click to Admin section. You’ll log in using admin/admin: change this using htpasswd against the .htpasswd file in the admin directory. Now you need to add this to your main.cf in virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql_virtual_alias_maps.cf Replacing: - /usr/local/virtual with your mailbox base path In /usr/local/etc/postfix, create a file named ‘mysql_virtual_alias_maps.cf’ containing user = postfix Here and in the files that follow, replace the password for user postfix with the one you changed in DATABASE_MYSQL.TXT. Create mysql_virtual_domains_maps.cf with user = postfix Create mysql_virtual_mailbox_maps.cf user = postfix Now create the directory tree: cd /usr/local/virtual Now we need to configure dovecot. cp /usr/local/etc/dovecot-example.conf /usr/local/etc/dovecot.conf, and edit dovecot.conf changing: - disable_plaintext_auth = no Uncomment and complete this: passdb sql { Create a file named ‘/usr/local/etc/dovecot-mysql.conf’ containing driver = mysql user_query = SELECT concat('/usr/local/virtual/', maildir) as home, concat('maildir:/usr/local/virtual/', maildir) as mail, 125 AS uid, 125 AS gid, concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' password_query = SELECT username as user, password, concat('/usr/local/virtual/', maildir) as userdb_home, concat('maildir:/usr/local/virtual/', maildir) as userdb_mail, 125 as userdb_uid, 125 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1' default_pass_scheme = PLAIN Check for the text in red to match your setup (125 = postfix gid, /usr/local/virtual/ = mailbox root). Let’s install SquirrelMail cd /usr/ports/mail/squirrelmail As we have done for Postfixadmin, lets create a virtual host pointing to /usr/local/www/squirrelmail, then: cd /usr/local/www/squirrelmail And set all the parameters you need. I use to change option 2.3 from SMTP to SENDMAIL. That’s all! Now point your browser to the home of your SquirrelMail server and you’re ready. Now let’s install an antivirus: ClamAV cd /usr/ports/security/clamav leaving the default options Similarly, for Amavis: cd /usr/ports/security/amavisd-new This is the interface between the antivirus software and the mail server. In the bitmap you can see I decided to enable some compression formats that were disabled by default. You’ll get several perl dependencies here. Also when installing spamassassin you’ll be asked if you want to update it: for now respond No. Now we have to add user clamav to the vscan group: edit /etc/groups, find the line with vscan and modify as: vscan:*:110:clamav Now, entering the command id clamav you should get an answer similar to (note the red part): uid=106(clamav) gid=106(clamav) groups=106(clamav), 6(mail), 110(vscan). Write them down. I obtained clamav=106 and vscan=110. Edit the file /usr/local/etc/amavisd.conf by setting the correct values for $mydomain and $myhostname, that is something like: Now indicate Amavisd that we have the ClamAV scanner. Edit /usr/local/etc/amavisd.conf: find the lines below and uncomment them (not the first one, obviously). Add the various _enable lines to your rc.conf file so that programs can start clamav_clamd_enable="YES" I commented out the last one. Decide based on your needs. And then start them /usr/local/etc/rc.d/clamav-freshclam start You should see several messages. Now let’s integrate postfix and Amavisd: edi t /usr/local/etc/postfix/main.cf and add: content_filter = smtp-amavis:[127.0.0.1]:10024 Postfix will send content to the filter on port 10024. Once scanned the message will be back to postfix, so edit /usr/local/etc/postfix/master.cf and tell postfix to listen also on port 10025. # AMaVIs interface for postfix smtp-amavis unix - - n - 2 smtp 127.0.0.1:10025 inet n- n - - smtpd Referencies Writing this document involved lots of experimenting and readings. In particular from www.freebsddiary.org for FreeBSD specific information and from bliki.rimuhosting.com for Linux information. |



