Professional Documents
Culture Documents
Use promo code DOCS10 for $10 credit on a new account. Try this Guide
Contribute on GitHub
View Project (https://github.com/linode/docs) | View File (https://github.com/linode/docs/blob/master/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6.md) | Edit File
(https://github.com/linode/docs/edit/master/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6.md)
The Postx Mail Transfer Agent (MTA) is a high performance open source e-mail server system. This guide will help you get Postx running on
your CentOS 6 Linode, using Dovecot for IMAP/POP3 service, and MySQL to store information on virtual domains and users.
Prior to using this guide, be sure you have followed the getting started guide (/docs/getting-started/) and set your hostname.
Note
The steps in this guide require root privileges. Be sure to run the steps below as root , or use su - root to log in as root. Certain commands below
cannot be run as sudo and must be run as root.
1 yum update
2. The version of Postx included in the main CentOS repository does not include support for MySQL; therefore, you will need install Postx
from the CentOS Plus repository. Before doing so, add exclusions to the [base] and [updates] repositories for the Postx package to
prevent it from being overwritten with updates that do not have MySQL support:
This installs the Postx mail server, the MySQL database server, the Dovecot IMAP and POP daemons, and several supporting packages
that provide services related to authentication.
1 chkconfig mysqld on
2 service mysqld start
2. Run mysql_secure_installation . You will be presented with the opportunity to change the MySQL root password, remove anonymous
user accounts, disable root logins outside of localhost, remove test databases, and reload privilege tables. It is recommended that you
answer yes to these options:
1 mysql_secure_installation
1 mysql -u root -p
5. Create a mail administration user called mail_admin and grant it permissions on the mail database. Please be sure to replace
mail_admin_password with a strong password:
1 CREATE TABLE domains (domain varchar(50) NOT NULL, PRIMARY KEY (domain) );
1 CREATE TABLE forwardings (source varchar(80) NOT NULL, destination TEXT NOT NULL, PRIMARY KEY (source) );
1 CREATE TABLE users (email varchar(80) NOT NULL, password varchar(20) NOT NULL, PRIMARY KEY (email) );
1 CREATE TABLE transport ( domain varchar(128) NOT NULL default '', transport varchar(128) NOT NULL default '', UNIQUE KEY domain
1 quit
11. Bind MySQL to localhost (127.0.0.1) by editing /etc/my.cnf , and adding the following to the [mysqld] section of the le:
1 bind-address=127.0.0.1
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 2/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
This is required for Postx to be able to communicate with the database server. If you have MySQL set up to listen on another IP address
(such as an internal IP), you will need to substitute this IP address in place of 127.0.0.1 during the Postx conguration steps. It is not
advisable to run MySQL on a publicly-accessible IP address.
Next, perform additional Postx conguration to set up communication with the database.
File: /etc/postfix/mysql-virtual_domains.cf
1 user = mail_admin
2 password = mail_admin_password
3 dbname = mail
4 query = SELECT domain AS virtual FROM domains WHERE domain='%s'
5 hosts = 127.0.0.1
File: /etc/postfix/mysql-virtual_forwardings.cf
1 user = mail_admin
2 password = mail_admin_password
3 dbname = mail
4 query = SELECT destination FROM forwardings WHERE source='%s'
5 hosts = 127.0.0.1
File: /etc/postfix/mysql-virtual_mailboxes.cf
1 user = mail_admin
2 password = mail_admin_password
3 dbname = mail
4 query = SELECT CONCAT(SUBSTRING_INDEX(email,<'@'>,-1),'/',SUBSTRING_INDEX(email,<'@'>,1),'/') FROM users WHERE email='%s'
5 hosts = 127.0.0.1
File: /etc/postfix/mysql-virtual_email2email.cf
1 user = mail_admin
2 password = mail_admin_password
3 dbname = mail
4 query = SELECT email FROM users WHERE email='%s'
5 hosts = 127.0.0.1
1 chmod o= /etc/postfix/mysql-virtual_*.cf
2 chgrp postfix /etc/postfix/mysql-virtual_*.cf
6. Create a user and group for mail handling. All virtual mailboxes will be stored under this users home directory:
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 3/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
7. Complete the remaining steps required for Postx conguration. Please be sure to replace server.example.com with the Linodes fully
qualied domain name. If you are planning on using your own SSL certicate and key, replace /etc/pki/dovecot/private/dovecot.pem
with the appropriate path:
8. Edit the le /etc/postfix/master.cf and add the Dovecot service to the bottom of the le:
9. Congure Postx to start on boot and start the service for the rst time:
1 chkconfig postfix on
2 service postfix start
1 mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-backup
2. Copy the following into the now-empty dovecot.conf le, substituting your systems domain name for example.com in line 37:
File: /etc/dovecot/dovecot.conf
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 4/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
3. MySQL will be used to store password information, so /etc/dovecot/dovecot-sql.conf.ext must be created. Insert the following contents
into the le, making sure to replace mail_admin_password with your mail password:
File: /etc/dovecot/dovecot-sql.conf.ext
1 driver = mysql
2 connect = host=127.0.0.1 dbname=mail user=mail_admin password=mail_admin_password
3 default_pass_scheme = CRYPT
4 password_query = SELECT email as user, password FROM users WHERE email='%u';
4. Restrict access to the le by changing the permissions to allow users in the dovecot group to access it, while denying access to others:
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 5/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
5. Congure Dovecot to start on boot, and start it for the rst time:
1 chkconfig dovecot on
2 service dovecot start
6. Check /var/log/maillog to make sure Dovecot started without errors. Your log should have lines similar to the following:
1 Trying 127.0.0.1...
2 Connected to localhost.localdomain.
3 Escape character is '^]'.
4 +OK Dovecot ready.
9. Enter the command quit to return to your shell. This completes the Dovecot conguration. Next, youll make sure aliases are congured
properly.
File: /etc/aliases
1 postmaster: root
2 root: postmaster@example.com
1 newaliases
2 service postfix restart
This completes alias conguration. Next, test Postx to make sure its operating properly.
Testing Post x
1. Test Postx for SMTP-AUTH and TLS:
1 telnet localhost 25
1 ehlo localhost
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 6/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
1 250-hostname.example.com
2 250-PIPELINING
3 250-SIZE 30720000
4 250-VRFY
5 250-ETRN
6 250-STARTTLS
7 250-AUTH PLAIN
8 250-AUTH=PLAIN
9 250-ENHANCEDSTATUSCODES
10 250-8BITMIME
11 250 DSN
Next, populate the MySQL database with domains and email users.
In the following example, the MySQL shell is used to add support for the domain example.com, which will have an email account called sales.
1 mysql -u root -p
2. Switch to the mail database, add support for your domain, and create an email account. Be sure to replace example.com with your
domain name, sales@example.com with your chosen email, and password with a strong password:
1 USE mail;
2 INSERT INTO domains (domain) VALUES ('example.com');
3 INSERT INTO users (email, password) VALUES ('sales@example.com', ENCRYPT('password'));
4 quit
3. Prior to accessing any newly-created email account, a test message needs to be sent to create that users mailbox:
Press Ctrl+D to complete the message. You can safely leave the eld for Cc: blank. This completes the conguration for a new domain
and email user.
Note
Given the possibility for virtual hosting a large number of domains on a single mail system, the username portion of an email address (i.e. before the @
sign) is not sufcient for authentication. When email users authenticate to the server, they must supply the entire email address created above as their
username.
1. Check the maillog located in /var/log/maillog . You should see something similar to the following:
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 7/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
2. Check the Dovecot delivery log located in /home/vmail/dovecot-deliver.log . The contents should look similar to the following:
Now you can test to see what the users of your email server would see with their email clients.
1 cd /home/vmail/example.com/sales/Maildir
2 find
1 .
2 ./dovecot-uidlist
3 ./cur
4 ./new
5 ./new/1285609582.P6115Q0M368794.li172-137
6 ./dovecot.index
7 ./dovecot.index.log
8 ./tmp
3. Test the maillbox by using a mail client. For this test, using mutt is recommended. If it is not installed by default, install it with
yum install mutt , then run:
1 mutt -f .
You may be prompted to create the root mailbox. This is not required.
4. If there is an email in the inbox, Postx, Dovecot, and MySQL have been successfully congured! To quit mutt press q .
(/docs/assets/postxcentos-mutt.png)
More Information
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 8/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be
useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
ISP-style Email Server with Debian-Lenny and Postx 2.5 guide (http://workaround.org/ispmail/lenny)
Groupware Server With Group-Ofce, Postx, Dovecot And SpamAssassin On Debian Lenny (5.0) (http://www.howtoforge.com/groupware-
server-with-group-ofce-postx-dovecot-spamassassin-on-debian-lenny)
Postx MySQL Howto (http://www.postx.org/MYSQL_README.html)
Postx SASL Howto (http://www.postx.org/SASL_README.html)
Dovecot Documentation Wiki (http://wiki.dovecot.org/)
MySQL Documentation (http://dev.mysql.com/doc/)
Overview (https://www.linode.com/linodes)
Plans & Pricing (https://www.linode.com/pricing)
Features (https://www.linode.com/linodes)
Add-Ons (https://www.linode.com/addons)
Managed (https://www.linode.com/managed)
Resources (https://www.linode.com/docs)
Guides & Tutorials (https://www.linode.com/docs)
Forum (https://forum.linode.com/)
Chat (https://www.linode.com/chat)
Company (https://www.linode.com/about)
About Us (https://www.linode.com/about)
Blog (https://blog.linode.com)
Press (https://www.linode.com/press)
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 9/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
Careers (https://www.linode.com/careers)
Contact Us (https://www.linode.com/contact)
855-4-LINODE (tel:+18554546633)
(855-454-6633) (tel:+18554546633)
Email us (mailto:support@linode.com)
Security (https://www.linode.com/security)
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 10/11
16/3/2017 Email with Postx, Dovecot and MySQL on CentOS 6
https://www.linode.com/docs/email/postx/email-with-postx-dovecot-and-mysql-on-centos-6 11/11