// <ahref="./index.html">Document Index</a></div><h1id="integrate-dbmail-with-iredmail-mysql-backend-on-centos">Integrate DBMail with iRedMail (MySQL backend) on CentOS</h1>
<li><ahref="#test-saslauthd-and-troubleshooting">Test saslauthd and troubleshooting</a></li>
<li><ahref="#enable-cyrus-sasl-in-postfix">Enable Cyrus-SASL in Postfix</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<h2id="changelog">ChangeLog</h2>
<ul>
<li>2011-10-26: Cleanup unnecessary process for installing DBMail.</li>
<li>2011-08-27: Initial release.</li>
</ul>
<h2id="requirements">Requirements</h2>
<p>This tutorial is written for:</p>
<ul>
<li>Red Hat Enterprise Linux 5.x, 6.x</li>
<li>CentOS 5.x, 6.x</li>
<li>Scientific Linux 6.x</li>
</ul>
<h2id="introduce-dbmail">Introduce DBMail</h2>
<h3id="what-dbmail-is">What DBMail is</h3>
<p>DBMail is an open-source project that enables storage of mail messages in a relational database. Currently MySQL, PostgreSQL and SQLite can be used as storage backends. Web site: <ahref="http://www.dbmail.org/">http://www.dbmail.org/</a>.</p>
<h3id="why-dbmail">Why DBMail</h3>
<p>Quote from DBMail web site:</p>
<blockquote>
<ul>
<li><strong>Scalability</strong>. DBMail is as scalable as the database system used for storage.</li>
<li><strong>Manageability</strong>. DBMail can be managed by updating the relational database or directory service - without shell access.</li>
<li><strong>Speed</strong>. Dbmail uses very efficient, database specific queries for retrieving mail information.</li>
<li><strong>Security</strong>. Dbmail doesn't require filesystem access. It's as secure as the database and directory server used. </li>
<li><strong>Flexibility</strong>. Changes in a Dbmail system (adding of users, changing passwords etc.) are effective immediately. Users can be stored in the database, or managed separately in an LDAP server such as OpenLDAP or Active Directory.</li>
</ul>
</blockquote>
<p>Notes:</p>
<ul>
<li>For RHEL/CentOS/Scientific Linux 5.x, we will install DBMail-2.2.17 from <ahref="http://fedoraproject.org/wiki/EPEL">yum repo <code>EPEL</code></a>.</li>
<li>For RHEL/CentOS/Scientific Linux 6.x, we will install DBMail-3.0.0-rc from <ahref="http://fedoraproject.org/wiki/EPEL">yum repo <code>EPEL</code></a>.</li>
<li>DBMail-2.x doesn't provide native TLS/SSL support.</li>
</ul>
<h2id="preparations">Preparations</h2>
<ul>
<li>
<p>OS:</p>
<ul>
<li>Red Hat Enterprise Linux 5.x or 6.x</li>
<li>CentOS 5.x or 6.x</li>
<li>Scientific Linux 5.x or 6.x</li>
</ul>
</li>
<li>
<p>A running iRedMail server. MySQL server is installed by default in both OpenLDAP and MySQL backends, so either backend is OK. If you don't have a running iRedMail server, please follow our installation guide here: <ahref="http://www.iredmail.org/doc.html">http://www.iredmail.org/doc.html</a>.</p>
</li>
<li>
<p>DBMail version:</p>
<ul>
<li>3.0.0 serial: 3.0.0-rc2 or later versions. There's a compatibility issue in DBMail-3.0.0-rc1, it won't work with Cyrus-SASL for SMTP AUTH.</li>
<li>Create MySQL database <code>dbmail</code> to store mail accounts and mail messages. Replace <code>password_of_dbmail</code> below with your password.</li>
</ul>
<pre><codeclass="sql">$ mysql -uroot -p
mysql> CREATE DATABASE dbmail DEFAULT CHARACTER SET utf8;
mysql> GRANT ALL ON dbmail.* TO dbmail@localhost IDENTIFIED BY 'password_of_dbmail';
mysql> FLUSH PRIVILEGES;
</code></pre>
<p>We now have a MySQL database <code>dbmail</code>, you can access it with MySQL user <code>dbmail</code> and password <code>password_of_dbmail</code>. You can verify it with MySQL command line:</p>
<pre><codeclass="sql">$ mysql -udbmail -p
Enter password: # <- Type password of MySQL user dbmail here.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| dbmail | # <- Database 'dbmail' is available.
+--------------------+
2 rows in set (0.04 sec)
</code></pre>
<ul>
<li>Stop Dovecot daemon. Since Dovecot will be replaced by DBMail, we must stop it:</li>
</ul>
<pre><code># /etc/init.d/dovecot stop
# chkconfig --level 345 dovecot off
</code></pre>
<h3id="install-dbmail">Install DBMail</h3>
<p>DBMail is available in <ahref="http://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F">EPEL repository</a>, we will use this yum repository to install DBMail.</p>
<p>It's now ready to install DBMail core component and library used to connect MySQL.</p>
<p>On RHEL/CentOS/Scientific Linux 6.x, please make sure you have DBMail 3.0.0-rc3 or later version installed:</p>
<pre><code># rpm -q dbmail
dbmail-3.0.0-0.6.rc3.el6.x86_64
</code></pre>
<p>Main configure file of DBMail is <code>/etc/dbmail.conf</code> by default, we will configure it later.</p>
<p>DBMail provides a MySQL template file <code>/usr/share/doc/dbmail-x.y.z/sql/mysql/create_tables.mysql</code> (replace 'x.y.z' by real version number on your server), we should import it to create necessary MySQL tables to store mail accounts and messages. Here we use 'dbmail-3.0.0' for example.</p>
<p>DBMail daemons are running, let's create a testing account to test POP3/POP3S/IMAP/IMAPS/Managesieve services.</p>
<ul>
<li>Create a testing account <code>test@domain.ltd</code>, with password <code>mypass</code>:</li>
</ul>
<pre><code># dbmail-users -p md5 -a test@domain.ltd -w mypass -s test@domain.ltd
Adding INBOX for new user... ok.
[test@domain.ltd]
Done
test@domain.ltd:x:5:0:0.00:0.00:test@domain.ltd
</code></pre>
<p>Refer to DBMail wiki site for more information about managing users: http://dbmail.org/dokuwiki/doku.php/manage_users</p>
<h3id="test-pop3imapmanagesieve-services-with-telnet">Test POP3/IMAP/Managesieve services with telnet</h3>
<p>It's OK to test POP3/POP3S/IMAP/IMAPS services with telnet, mutt or Roundcube webmail, here we use telnet and mutt instead. After testing, you can login to Roundcube Webmail directly.</p>
<p>Update postfix setting in <code>/etc/postfix/main.cf</code>, remove <code>reject_unknown_sender_domain</code> in <code>smtpd_recipient_restrictions</code> setting.</p>
</li>
<li>
<p>Update postfix setting to lookup mail users and aliases from DBMail MySQL database:</p>
<p>Restart Apache, you can now view sent email after logging into Roundcube webmail:</p>
<pre><code># /etc/init.d/httpd restart
</code></pre>
<h2id="replace-dovecot-with-cyrus-sasl-as-smtp-sasl-auth-daemon">Replace Dovecot with Cyrus-SASL as SMTP SASL auth daemon</h2>
<p>Postfix uses <code>dovecot</code> as SASL type in iRedMail by default, since Dovecot will be replaced by DBMail, we cannot use Dovecot anymore. So we're going to install Cyrus-SASL libraries, and use daemon 'saslauthd' for SMTP SASL auth.</p>
<p>In this section, we will:</p>
<ul>
<li>Install Cyrus-SASL libraries.</li>
<li>Configure Cyrus-SASL.</li>
<li>Running and testing Cyrus-SASL auth daemon 'saslauthd' immediately.</li>
<p>Note: If you're running DBMail-3.0.0-rc1, you will always get <code>0: NO "authentication failed"</code>, because DBMail-3.0.0-rc1 has a compatibility issue with Cyrus-SASL.</p>
<h3id="enable-cyrus-sasl-in-postfix">Enable Cyrus-SASL in Postfix</h3>
<p>You can now send email with Roundcube webmail.</p><divclass="footer">
<pstyle="text-align: center; color: grey;">All documents are available in <ahref="https://bitbucket.org/zhb/iredmail-docs/src">BitBucket repository</a>, and published under <ahref="http://creativecommons.org/licenses/by-nd/3.0/us/"target="_blank">Creative Commons</a> license. You can <ahref="https://bitbucket.org/zhb/iredmail-docs/get/tip.tar.bz2">download the latest version</a> for offline reading. If you found something wrong, please do <ahref="http://www.iredmail.org/contact.html">contact us</a> to fix it.</p>