Table Of ContentInstall postfix on Debian Wheezy Linux / Postfix mail server with
Dovecot and MySQL user storage on Debian Wheezy 7 Linux
Author : admin
I have recently installed Postfix on a server following WorkAround.org ISPMail Tutorial on Debian
Wheezy Linux 7. Officially as you can see on their website there is no official guide still for Debian
Wheezy yet. Therefore my only option was to follow ISPMail tutorial using Postfix 2.7 (Debian
Squeeze).
It was quite a struggle to adapt tutorial for Squeeze deb to Wheezy and it took me an overall time of
about of week (each day spending few hours trying to make various components of tutorial) work. But
finally I managed to install it. This is how this article got born in hope that in future it will help others
have a decent Postfix install on Wheezy..
For those unfamiliar with Workaround.org's ISPMail Postfix Tutorial it is pretty much standard step-by-
step installation guide for dummies similar to QmailRocks.org or Thibs QmailRocks Updated
Installation Guide.
In Other words Workaround.org is probably the best Postfix full featured install tutorial currently
online as of time of writting this post. Workaround.org is great for people who want to run full
featured;
Postfix SMTP configured to support;
Postfix to support Mail Virtual Domains (store E-mails in MySQL database)
Dovecot Secure IMAP / IMAPS / POP3 / POP3s server to offer Pop3 and Imap remote access
Support Properly Generated SSL Certificates for POP3s and IMAPs
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
1 / 12
http://www.pc-freak.net/blog
Anti Spam - SMTPD restrictions, SPF, RBL, Greylisting
Install web frontend to support Web E-mail Domaim / Accounts easy administrations for
users stored in MySQL db
Amavisd-New (to protect Mail server from Spam)
Postfix WebMail frontend with Roundcube or Squirrelmail
Here is the big picture as it gives good idea on how all above components correspond to each other:
So here we go:
1. Install Postfix necessary debian packages
a) Install Postfix / MySQL / phpmyadmin and Postfix support for MySQL mail storage deb packs
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
2 / 12
http://www.pc-freak.net/blog
apt-get update
apt-get upgrade
apt-get install --yes ssh
apt-get install --yes postfix postfix-mysql
apt-get --purge remove 'exim4*'
apt-get install --yes mysql-client mysql-server dovecot-common dovecot-imapd dovecot-pop3d postfix libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl telnet mailutils
apt-get install --yes mysql-server phpmyadmin
b) Install deb packages for Dovecot and Imap Support as well as Roundcube and / or Squirrelmail for
Webmail support
squirrelmail
apt-get install --yes dovecot-pop3d dovecot-imapd dovecot-lmtpd
c) Install packages deb packages for Anti-spam greylisting (tumgreyspf)
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
3 / 12
http://www.pc-freak.net/blog
apt-get install --yes tumgreyspf
2. Create necessary MySQL database structures
Next step is toconnect to MySQL as root via MySQL CLI or PhpMyadmin and CREATE new user
"mailuser" and new database "mailserver", then create basic structure for "mailserver" database - i.e. sql
tables ("virtual_domains", virtual_users", virtual_aliases")
These user and database is used laters by Dovecot server to connect and fetch emails from MySQL on
user request via POP3 or IMAP. I've taken all the SQL requests and from Workaround.org's site and
placed them in one SQL file:
create-postfix-mysql-user-database.sql.
Below is mysql cli query to import it. If you prefer more user friendliness do it via PhpMyAdmin with a
copy / paste from file or with PhpMyAdmin import ...
wget -q http://www.pc-freak.net/files/postfix/create-postfix-mysql-user-database.sql
mysql -u root -p
Link to create-postfix-mysql-user-database.sql is here
3. Setting up Dovecot required users and directories
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
4 / 12
http://www.pc-freak.net/blog
Next its necessary configure some users and create directories where Dovecot will store its configuration files. Dovecot requires to create its custom files for each existing users in MySQL database. Therefore whenever user receives or sends e-mail or is simply created Dovecot also creates a user
directory structure in /var/vmail/, for exmpl.:
# ls -al /var/vmail/mail-domain.org/test/mail/
total 20
drwx------ 4 vmail vmail 4096 jul 29 09:15 .
drwx------ 3 vmail vmail 4096 jul 29 07:20 ..
drwx------ 3 vmail vmail 4096 jul 29 09:15 .imap
drwx------ 2 vmail vmail 4096 jul 29 09:15 INBOX
-rw------- 1 vmail vmail 24 jul 29 09:15 .subscriptions
The functions of Dovecot server again are:
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
5 / 12
http://www.pc-freak.net/blog
Get emails from Postfix (MySQL database) and save them to disk
Allow mail users to fetch emails using POP3 or IMAP protocol with Outlook / Thunderbird whatever pop3 client
groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /var/vmail -m
chown -R vmail:vmail /var/vmail
chmod u+w /var/vmail
chgrp vmail /etc/dovecot/dovecot.conf
chmod g+r /etc/dovecot/dovecot.conf
chown root:root /etc/dovecot/dovecot-sql.conf
chmod go= /etc/dovecot/dovecot-sql.conf
4. Create self-signed SSL certificate for Postfix mail and Dovecot pop3 server
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
6 / 12
http://www.pc-freak.net/blog
openssl req -new -x509 -days 3650 -nodes -out /etc/ssl/certs/dovecot.pem -keyout /etc/ssl/private/dovecot.pem
chmod o= /etc/ssl/private/dovecot.pem
/etc/init.d/dovecot restart
openssl req -new -x509 -days 3650 -nodes -out /etc/ssl/certs/postfix.pem -keyout /etc/ssl/private/postfix.pem
chmod o= /etc/ssl/private/postfix.pem
5. Configuring Amavis (Anti Virus frontend) with Clamav AV
To reduce viruses it is a must nowadays to install Antivirus in Qmail I used qmail-scanner (perl script) frontend to Clamav Antivirus to check for Viruses and some messed up e-mails. In Postfix just like in Sendmail, tool that does the same is amavisd-new. There are some configuration files to do,
but as its time consuming to do changes one by one I prefer moving old /etc/amavis/ to /etc/amavis-bak/ and download and untar archive with already set proper configs
apt-get install --yes amavisd-new
useradd clamav -g amavis
mv /etc/amavis /etc/amavis-old
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
7 / 12
http://www.pc-freak.net/blog
cd /etc/
wget http://www.pc-freak.net/files/postfix/amavis-config-debian-wheezy-7.tar.gz
tar -zxvvf amavis-config-debian-wheezy-7.tar.gz
...
.....
/etc/init.d/amavis start
Starting amavisd: amavisd-new.
Amavisd is meant to communicate in two port numbers with Postfix. Postfix passes Input in one (10024) and Output - Scanned File Status in (10025). Thus for normal amavis operation this two ports has to be showing as listening on localhost, e.g.:
netstat -nap | grep -E '10024|10025'
tcp 0 0 127.0.0.1:10024 0.0.0.0:* LISTEN 13957/amavisd-new (
tcp 0 0 127.0.0.1:10025 0.0.0.0:* LISTEN 9007/master
6. Placing Dovecot working (properly configured) config files for Debian Wheezy
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
8 / 12
http://www.pc-freak.net/blog
On Workaround.org there are plenty of configurations to copy paste inside files and how it is explained is a bit complicated thus played a lot mainly with /etc/postfix/master.cf and /etc/postfix/main.cf configurations until I finally had a working version of (SMTP) configured not to be an open relay
and receive / sent email OK ...
Here are configurations that worked for me:
mv /etc/postfix /etc/postfix-old
cd /etc/
wget -q http://www.pc-freak.net/files/postfix/postfix-configs-debian-wheezy.tar.gz
tar -zxvvf postfix-configs-debian-wheezy.tar.gz
... .....
[ ok ] Stopping Postfix Mail Transport Agent: postfix.
[ ok ] Starting Postfix Mail Transport Agent: postfix.
To download my good postfixs-debian-wheezy.tar.gz look here
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
9 / 12
http://www.pc-freak.net/blog
Afterwards only setting you have to change in /etc/postfix/main.cf is:
myhostname = example-mail.org
to your Fully Qualified Domain Name (FQDN), lets say pc-freak.net
myhostname = pc-freak.net
I find it also useful to remove from SMTP after connect banner reporting that Postfix is running on Debian in main.cf change:
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
to
smtpd_banner = $myhostname ESMTP $mail_name
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
10 / 12
http://www.pc-freak.net/blog