VirtualUsersAndDomainsWithPostfix, Courier, MySQLAndS_MySQL

Source: Internet
Author: User
Tags imap squirrelmail fully qualified domain name
VirtualUsersAndDomainsWithPostfix, Courier, MySQLAndSquirrelMail (Ubuntu14.04LTS) Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Ubuntu 14.04LTS)

Version 1.0:
Author: Falko Timme, updated by Srijan Kishore
Last edited 30/Apr/2014

This tutorial is Copyright (c) 2014 by Falko Timme & Srijan Kishore. it is derived from a tutorial from Christoph Haas which you can find athttp: // workaround.org. you are free to use this tutorial under the Creative Commons license 2.5 or any later version.

This document describes how to install a Postfix mail server that is based on virtual users and domains, I. e. users and domains that are in a MySQL database. i'll also demonstrate the installation and configuration of Courier (Courier-POP3, Courier-IMAP), so that Courier can authenticate against the same MySQL database Postfix uses.

The resulting Postfix server is capableSMTP-AUTHAndTLSAndQuota(Quota is not built into Postfix by default, I'll show how to patch your Postfix appropriately). Passwords are stored inEncryptedForm in the database (most documents I found were dealing with plain text passwords which is a security risk). In addition to that, this tutorial covers the installationAmavisd,SpamAssassinAndClamAVSo that emails will be scanned for spam and viruses. I will also show how to installSquirrelMailAs a webmail interface so that users can read and send emails and change their passwords.

The advantage of such a "virtual" setup (virtual users and domains in a MySQL database) is that it is far more than T than a setup that is based on "real" system users. with this virtual setup your mail server can handle thousands of domains and users. besides, it is easier to administrate because you only have to deal with the MySQL database when you add new users/domains or edit existing ones. no more postmap commands to create db files, no more reloading of Postfix, etc. for the administration of the MySQL database you can use web based tools like phpMyAdmin which will also be installed in this howto. the third advantage is that users have an email address as user name (instead of a user name + an email address) which is easier to understand and keep in mind.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. there are always ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 Preliminary Note

This tutorial is based on Ubuntu 14.04 Server (Trusty Tahr), so you shocould set up a basic Ubuntu 14.04 server installation before you continue with this tutorial. the system shoshould have a static IP address. I use192.168.0.100as my IP address in this tutorial andserver1.example. comas the hostname.

Make sure that you are logged in as root (type in

Sudo su

To become root), because we must run all the steps from this tutorial as root user.

It is very important that you make/bin/sha symlink to/bin/bash...

Dpkg-reconfigure dash

Use dash as the default system shell (/bin/sh )? <-- No

... And that you disable AppArmor, if you are getting apparmor: unrecognized servicettings remove it from update-rc.d

Service apparmor stop
Update-rc.d-f apparmor remove
Apt-get remove apparmor-utils

2 Install Postfix, Courier, Saslauthd, MySQL, phpMyAdmin

To install Postfix, Courier, Saslauthd, MySQL, and phpMyAdmin, we simply run

Apt-get install postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop-ssl courier-imap- ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql libpam-smbpass

You will be asked a few questions:

New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
Create directories for web-based administration? <-- No
General type of mail configuration: <-- Internet Site
System mail name: <-- server1.example.com
SSL certificate required <-- OK
Web server to reconfigure automatically: <-- apache2
Configure database for phpmyadmin with dbconfig-common? <-- No

3 Apply The Quota Patch To Postfix

We have to get the Postfix sources, patch it with the quota patch, build new Postfix. debpackages and install those. debpackages:

Apt-get build-dep postfix

Some time you can get an error as follows :-

Root @ server1 :~ # Apt-get build-dep postfix
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: You must put some 'source' URIs in your sources. list
Root @ server1 :~ #

You can correct it as follows, by adding the source repositories:

Vi/etc/apt/sources. list

Make the entry as in my case is

Deb http://archive.ubuntu.com/ubuntu trusty main restricted universe
Deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe
Deb http://security.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
Deb http://archive.canonical.com/ubuntu trusty partner
The deb-src http://archive.ubuntu.com/ubuntu trusty main restricted universe
Deb-src http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe
Deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
The deb-src http://archive.canonical.com/ubuntu trusty partner

Next

Apt-get update
Apt-get build-dep postfix

Cd/usr/src
Apt-get source postfix

(Make sure you use the correct Postfix version in the following commands. I have Postfix 2.11.0 installed. You can find out your Postfix version by running

Postconf-d | grep mail_version

The output shoshould look like this:

Root @ server1:/usr/src # postconf-d | grep mail_version
Mail_version = 2.11.0
Milter_macro_v = $ mail_name $ mail_version
Root @ server1:/usr/src #

Wget http://vda.sourceforge.net/VDA/postfix-vda-v13-2.10.0.patch
Cd postfix-2.11.0
Patch-p1 <../postfix-vda-v13-2.10.0.patch

Next opendebian/rulesand changeDEB_BUILD_HARDENINGfrom1to0:

Vi debian/rules

[...]export DEB_BUILD_HARDENING=0[...]

If you don't do this, your build will fail with the following error messages:

Maildir. c: In function â deliver _ maildir â:
Maildir. c: 974: 17: error: format not a string literal and no format arguments [-Werror = format-security]
Maildir. c: 977: 17: error: format not a string literal and no format arguments [-Werror = format-security]
Maildir. c: 983: 17: error: format not a string literal and no format arguments [-Werror = format-security]
Maildir. c: 986: 17: error: format not a string literal and no format arguments [-Werror = format-security]
Maildir. c: In function â sql2file â:
Maildir. c: 404: 25: warning: ignoring return value of â readâ, declared with attribute warn_unused_result [-Wunused-result]
Maildir. c: 417: 26: warning: ignoring return value of â write â, declared with attribute warn_unused_result [-Wunused-result]
C0: some warnings being treated as errors
Make: *** [maildir. o] Error 1
Make: Leaving directory '/usr/src/postfix-2.11.0/src/virtual'
Make [1]: *** [update] Error 1
Make [1]: Leaving directory '/usr/src/postfix-100'
Make: *** [build] Error 2
Dpkg-buildpackage: error: debian/rules build gave error exit status 2
Root @ server1:/usr/src/postfix-2.11.0 #

Now we can build the new Postfix. debpackages:

Dpkg-buildpackage

Now we go one directory up, that's where the new. debpackages have been created:

Cd ..

The command

Ls-l

Shows you the available packages:

Root @ server1:/usr/src # ls-l
Total 6824
Drwxr-xr-x 18 root 4096 Apr 30 postfix-2.11.0
-Rw-r -- 1 root 46756 Apr 30 postfix-cdb_2.11.0-1_amd64.deb
-Rw-r -- 1 root 142842 Apr 30 postfix-dev_2.11.0-1_all.deb
-Rw-r -- 1 root 851842 Apr 30 postfix-doc_2.11.0-1_all.deb
-Rw-r -- 1 root 53898 Apr 30 postfix-ldap_2.11.0-1_amd64.deb
-Rw-r -- 1 root 48500 Apr 30 postfix-mysql_2.11.0-1_amd64.deb
-Rw-r -- 1 root 48610 Apr 30 postfix-pcre_2.11.0-1_amd64.deb
-Rw-r -- 1 root 48324 Apr 30 postfix-pgsql_2.11.0-1_amd64.deb
-Rw-r -- 1 root 55701 Jun 7 2013 postfix-vda-v13-2.10.0.patch
-Rw-r -- 1 root 267855 Apr 30 postfix_2.11.0-1.diff.gz
-Rw-r -- 1 root 1522 Apr 30 postfix_2.11.0-1.dsc
-Rw-r -- 1 root 3885 Apr 30 postfix_2.11.0-1_amd64.changes
-Rw-r -- 1 root 1329238 Apr 30 postfix_2.11.0-1_amd64.deb
-Rw-r -- 1 root 4034741 Feb 12 0:38 postfix_2.11.0.orig.tar.gz
Root @ server1:/usr/src #

Pick thepostfixandpostfix-mysqlpackages and install them like this:

Dpkg-I postfix_2.11.0-1_amd64.deb postfix-mysql_2.11.0-1_amd64.deb

4 Create The MySQL Database For Postfix/Courier

Now we create a database calledmail:

Mysqladmin-u root-p create mail

You will be asked for this question:

Enter Password: <-- yourrootsqlpassword

Next, we go to the MySQL shell:

Mysql-u root-p

On the MySQL shell, we create the usermail_adminwith the passwortmail_admin_password (replace it with your own password) who hasSELECT, INSERT, UPDATE, DELETEprivileges on themaildatabase. this user will be used by Postfix and Courier to connect to the mail database:

Grant select, INSERT, UPDATE, delete on mail. * TO 'mail _ admin' @ 'localhost' identified by 'mail _ admin_password ';
Grant select, INSERT, UPDATE, delete on mail. * TO 'mail _ admin' @ 'localhost. localdomain 'identified BY 'mail _ admin_password ';
Flush privileges;

Still on the MySQL shell, we create the tables needed by Postfix and Courier:

USE mail;

Create table domains (
Domain varchar (50) not null,
Primary key (domain ))
ENGINE = MyISAM;

Create table forwardings (
Source varchar (80) not null,
Destination text not null,
Primary key (source ))
ENGINE = MyISAM;

Create table users (
Email varchar (80) not null,
Password varchar (20) not null,
Quota INT (10) DEFAULT '20140901 ',
Primary key (email)
) ENGINE = MyISAM;

Create table transport (
Domain varchar (128) not null default '',
Transport varchar (128) not null default '',
Unique key domain (domain)
) ENGINE = MyISAM;

Quit;

As you may have noticed, with thequit; command we have left the MySQL shell and are back on the Linux shell.

TheDomainsTable will store each virtual domain that Postfix shold receive emails for (e.g.Example.com).

Domain
Example.com

TheForwardingsTable is for aliasing one email address to another, e.g. forward emailsInfo@example.comToSales@example.com.

Source Destination
Info@example.com Sales@example.com

TheUsersTable stores all virtual users (I. e. email addresses, because the email address and user name is the same) and passwords (inEncryptedForm !) And a quota value for each mail box (in this example the default value is 10485760 bytes which means 10 MB ).

Email Password Quota
Sales@example.com No9.E4skNvGa. ("secret" in encrypted form) 10485760

TheTransportTable is optional, it is for advanced users. It allows to forward mails for single users, whole domains or all mails to another server. For example,

Domain Transport
Example.com Smtp: [1.2.3.4]

Wocould forward all emailsExample.comVia the smtp protocol to the server with the IP address1.2.3.4(The square brackets[]Mean "do not make a lookup of the mx dns record" (which makes sense for IP addresses ...). if you use a fully qualified domain name (FQDN) instead you wocould not use the square brackets .).

BTW, (I'm assuming that the IP address of your mail server system is192.168.0.100) you can access phpMyAdmin overhttp: // 192.168.0.100/phpmyadmin/in a browser and log in asmail_admin. then you can have a look at the database. later on you can use phpMyAdmin to administrate your mail server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.