Postfix Virtual Hosting With LDAP Backend And With Dovecot As IMAP/POP3 Server On Ubuntu Trusty Tahr 14.04 - Page 3
This tutorial exists for these OS versions
- Ubuntu 18.04 (Bionic Beaver)
- Ubuntu 14.04 LTS (Trusty Tahr)
- Ubuntu 9.10 (Karmic Koala)
- Ubuntu 8.10 (Intrepid Ibex)
- Ubuntu 8.04 (Hardy Heron)
On this page
Step 3: Install And Configure Postfix
Before this we need to have the vmail user and its home directory.
Create the vmail user and group:
useradd vmail
By default the group vmail is created, too.
Check /etc/passwd for the actual uid and group number.
Next create the vmail directory and set ownership to the vmail user and group.
mkdir /home/vmail
mkdir /home/vmail/domains
chown -R vmail:vmail /home/vmail
Run the following command to install Postfix and other required applications:
apt install postfix postfix-ldap
You will be asked two questions. Answer as follows:
General type of mail configuration: <--Stand alone
System mail name: <-- mail.example.tld
We do not install sasl since we will use the Dovecot LDA and deliver.
Now we create the certificates for TLS:
mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
openssl rsa -in smtpd.key -out smtpd.key.unencrypted
mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
Now we will configure postfix:
cd /etc/postfix
mv /etc/postfix/main.cf /etc/postfix/main.cf.bck
vi /etc/postfix/main.cf
And paste the following into it. Please not that this config allows the sending (relaying) of mails by authenticated users, and also the sending of local mails (like for example to root, postmaster, ...) to the respective aliases if they are configured.
vi /etc/postfix/master.cf
And paste the following into it (add the end):
dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${recipient}
gnarwl unix - n n - - pipe
flags=F user=vmail argv=/usr/bin/gnarwl -a ${user}@${nexthop} -s ${sender}
Now we need to write the different ldap-xxx.cf files
vi ldap-accounts.cf
And paste the following in to it:
server_host = localhost
server_port = 389
version = 3
bind = yes
start_tls = no
bind_dn = cn=phamm,o=hosting,dc=example,dc=tld
bind_pw = readmonly
search_base = o=hosting,dc=example,dc=tld
scope = sub
query_filter = (&(&(objectClass=VirtualMailAccount)(mail=%s))(forwardActive=FALSE)(accountActive=TRUE)(delete=FALSE))
result_attribute = mailbox
vi ldap-accounstmap.cf
And paste the following in to it:
server_host = localhost
server_port = 389
version = 3
bind = yes
start_tls = no
bind_dn = cn=phamm,o=hosting,dc=example,dc=tld
bind_pw = readonly
search_base = o=hosting,dc=example,dc=tld
scope = sub
query_filter = (&(&(objectClass=VirtualMailAccount)(mail=%s))(forwardActive=FALSE)(accountActive=TRUE)(delete=FALSE))
result_attribute = mail
vi ldap-aliases.cf
And paste the following in to it:
server_host = localhost
server_port = 389
version = 3
bind = yes
start_tls = no
bind_dn = cn=phamm,o=hosting,dc=example,dc=tld
bind_pw = readonly
search_base = o=hosting,dc=example,dc=tld
scope = sub
query_filter = (&(&(objectClass=VirtualMailAlias)(mail=%s))(accountActive=TRUE))
result_attribute = maildrop
vi ldap-transport.cf
And paste the following in to it:
server_host = localhost
server_port = 389
version = 3
bind = yes
start_tls = no
bind_dn = cn=phamm,o=hosting,dc=example,dc=tld
bind_pw = readonly
search_base = o=hosting,dc=example,dc=tld
scope = sub
query_filter = (&(&(vd=%s)(objectClass=VirtualDomain))(accountActive=TRUE)(delete=FALSE))
result_attribute = postfixTransport
vi ldap-vacation.cf
And paste the following in to it:
server_host = localhost
server_port = 389
version = 3
bind = yes
start_tls = no
bind_dn = cn=phamm,o=hosting,dc=example,dc=tld
bind_pw = readonly
search_base = o=hosting,dc=example,dc=tld
scope = sub
query_filter = (&(&(objectClass=VirtualMailAccount)(mail=%s))(vacationActive=TRUE)(forwardActive=FALSE)(accountActive=TRUE)(delete=FALSE))
result_attribute = mailAutoreply
vi ldap-virtualforward.cf
And paste the following in to it:
server_host = localhost
server_port = 389
version = 3
bind = yes
start_tls = no
bind_dn = cn=phamm,o=hosting,dc=example,dc=tld
bind_pw = readonly
search_base = o=hosting,dc=example,dc=tld
scope = sub
query_filter = (&(&(objectClass=VirtualMailAccount)(mail=%s))(vacationActive=FALSE)(forwardActive=TRUE)(accountActive=TRUE)(delete=FALSE))
result_attribute = maildrop
This concludes the postfix setup.