12
Walking in Light with Christ - Faith, Computing, Diary Articles & tips and tricks on GNU/Linux, FreeBSD, Windows, mobile phone articles, religious related texts http://www.pc-freak.net/blog Install 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 1 / 12

Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Embed Size (px)

DESCRIPTION

Panduan Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Citation preview

Page 1: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://www.pc-freak.net/blog

Install postfix on Debian Wheezy Linux / Postfix mail server withDovecot 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 DebianWheezy Linux 7. Officially as you can see on their website there is no official guide still for DebianWheezy yet. Therefore my only option was to follow ISPMail tutorial using Postfix 2.7 (DebianSqueeze).

It was quite a struggle to adapt tutorial for Squeeze deb to Wheezy and it took me an overall time ofabout of week (each day spending few hours trying to make various components of tutorial) work. Butfinally I managed to install it. This is how this article got born in hope that in future it will help othershave 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 UpdatedInstallation Guide. In Other words Workaround.org is probably the best Postfix full featured install tutorial currentlyonline as of time of writting this post. Workaround.org is great for people who want to run fullfeatured;

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 accessSupport Properly Generated SSL Certificates for POP3s and IMAPs

1 / 12

Page 2: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://www.pc-freak.net/blog

Anti Spam - SMTPD restrictions, SPF, RBL, GreylistingInstall web frontend to support Web E-mail Domaim / Accounts easy administrations forusers stored in MySQL dbAmavisd-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

2 / 12

Page 3: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://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 forWebmail support

squirrelmail

apt-get install --yes dovecot-pop3d dovecot-imapd dovecot-lmtpd

c) Install packages deb packages for Anti-spam greylisting (tumgreyspf)

3 / 12

Page 4: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://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. sqltables ("virtual_domains", virtual_users", virtual_aliases")These user and database is used laters by Dovecot server to connect and fetch emails from MySQL onuser request via POP3 or IMAP. I've taken all the SQL requests and from Workaround.org's site andplaced 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

4 / 12

Page 5: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://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:

5 / 12

Page 6: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://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

6 / 12

Page 7: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://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

7 / 12

Page 8: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://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

8 / 12

Page 9: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://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

9 / 12

Page 10: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://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

10 / 12

Page 11: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://www.pc-freak.net/blog

7. Placing Dovecot working config files in /etc/

Configuring Dovecot is not an easy task in Debian Linux Squeeze and Lenny, on Postfix ISPMail guide there is a special tutorial for each as there is none yet for Debian Wheezy. It took me long to figure it out how to translate from old config settings for Wheezy's Dovecot 2.1.7-7. Configuration files

places has changed for some clarity in Dovecot 2.1.7-7. So many of the Workaround.rog's Squeeze Tutorial suggested changes in /etc/dovecot/dovecot.conf are to be made in files under /etc/dovecot/conf.d

Therefore quickest way to have working Dovecot is to move default config dir /etc/dovecot to /etc/dovecot-old and place tuned configs:

cd /etc/

wget -q http://www.pc-freak.net/files/postfix/dovecot-configs-debian-wheezy.tar.gz

tar -zxvvf dovecot-configs-debian-wheezy.tar.gz

...

....

chown -R vmail:dovecot /etc/dovecot

/etc/init.d/dovecot restart

quit

Connection closed.

11 / 12

Page 12: Install Postfix Mail Server Dovecot Mysql User Storage Debian Wheezy 7 Linux

Walking in Light with Christ - Faith, Computing, DiaryArticles & tips and tricks on GNU/Linux, FreeBSD, Windows,mobile phone articles, religious related textshttp://www.pc-freak.net/blog

Well this is the end my friend :) You should now have a properly running Postfix + Dovecot + Virtual Domainsin SQL. Please drop me a thank you comment if it worked for you. If it doesn't drop a comment so I can integrateit and improve this tutorial. Happy Hacking ;)

Powered by TCPDF (www.tcpdf.org)

12 / 12