{"id":5345,"date":"2018-07-11T12:23:47","date_gmt":"2018-07-11T08:23:47","guid":{"rendered":"https:\/\/www.howtoforge.com\/tutorial\/postfix-virtual-hosting-with-ldap-backend-and-dovecot-imap-pop3-server-on-ubuntu-bionic-beaver-1804-lts\/"},"modified":"2018-07-11T12:23:47","modified_gmt":"2018-07-11T08:23:47","slug":"postfix-virtual-hosting-with-ldap-backend-and-with-dovecot-as-imap-pop3-server-on-ubuntu-bionic-beaver-18-04-lts","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/postfix-virtual-hosting-with-ldap-backend-and-with-dovecot-as-imap-pop3-server-on-ubuntu-bionic-beaver-18-04-lts\/","title":{"rendered":"Postfix Virtual Hosting With LDAP Backend And With Dovecot As IMAP\/POP3 Server On Ubuntu Bionic Beaver 18.04 LTS"},"content":{"rendered":"<p>This howto will describe how to set up and configure virtual mail hosting with an\u00a0LDAP backend.<\/p>\n<p>The software\u00a0we will use in this howto:<span>\u00a0<a href=\"http:\/\/postfix.org\" target=\"_blank\" rel=\"noopener noreferrer\">Postfix<\/a>\u00a0(MTA), <a href=\"http:\/\/dovecot.org\" target=\"_blank\" rel=\"noopener noreferrer\">Dovecot<\/a>\u00a0(IMAP \/ POP3),<\/span><span><a href=\"http:\/\/www.postfix.org\" target=\"_blank\" rel=\"noopener noreferrer\">\u00a0<\/a><a href=\"https:\/\/github.com\/fln\/gnarwl\" target=\"_blank\" rel=\"noopener noreferrer\">Gnarwl<\/a>\u00a0(vacation), <a href=\"https:\/\/www.openldap.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">OpenLDAP<\/a>\u00a0(LDAP)\u00a0 and\u00a0<a href=\"https:\/\/github.com\/wolfman68\/vMailpanel\" target=\"_blank\" rel=\"noopener noreferrer\">vMailpanel<\/a> as the management interface.<\/span><\/p>\n<p><span>Optional are<a href=\"http:\/\/www.postfix.org\" target=\"_blank\" rel=\"noopener noreferrer\">\u00a0<\/a><a href=\"http:\/\/www.proftpd.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Proftpd<\/a>\u00a0FTP,\u00a0<a href=\"https:\/\/roundcube.net\/\" target=\"_blank\" rel=\"noopener noreferrer\">Roundcube<\/a>\u00a0(webmail) and\u00a0<a href=\"https:\/\/mariadb.org\/\" target=\"_blank\" rel=\"noopener\">MariaDB<\/a> (SQL backend for Roundcube).<\/span><\/p>\n<p>This worked for me, but I cannot guarantee that this set up will work for you so this howto comes without any guarantee.<\/p>\n<p><b>Assumptions<\/b><\/p>\n<p>This how-to assumes the following configurations, if your installation differs from this, then replace the entries below with your actual configuration.<\/p>\n<p>Mail delivery (mailboxes) path:<\/p>\n<p class=\"system\">\/home\/vmail\/<\/p>\n<p>User<span>\u00a0<\/span><span class=\"system\">vmail<\/span>:<\/p>\n<p class=\"system\">UID:1000, GID:1000<\/p>\n<p>User<span>\u00a0<\/span><span class=\"system\">postfix<\/span>:<\/p>\n<p class=\"system\">UID: 108, GID:108<\/p>\n<p>OpenLDAP base dn:<\/p>\n<p class=\"system\">dc=example,dc=tld<\/p>\n<p>OpenLDAP admin account:<\/p>\n<p class=\"system\">cn=admin,dc=example,dc=tld<\/p>\n<p>vMailpanel search dn:<\/p>\n<p class=\"system\">o=hosting,dc=example,dc=tld<\/p>\n<p>A read only account for the o=hosting,dc=example,dc=tld tree:<\/p>\n<p class=\"system\">cn=vmail,o=hosting,dc=example,dc=tld<\/p>\n<p>You&#8217;re using root as the user during this guide.\u00a0<\/p>\n<p>If you want for example o=maildomains or ou=domains, please make sure to replace o=hosting with what you\u00a0 want, especially in the acl.ldif. This acl file is strict, phamm will not work correctly if it is not exactly as it should be. If you want a different read only user than phamm than replace cn=phamm with cn=wat-you everywhere in this how to.<\/p>\n<p>This guide also assumes that you have installed and configured your Ubuntu server to your needs, there are plenty of good guides on<span>\u00a0<\/span><a href=\"https:\/\/www.howtoforge.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Howtoforge<\/a><span>\u00a0<\/span>for example:<\/p>\n<p><a href=\"https:\/\/www.howtoforge.com\/tutorial\/perfect-server-ubuntu-18.04-with-apache-php-myqsl-pureftpd-bind-postfix-doveot-and-ispconfig\/\" target=\"_blank\" rel=\"noopener\">The Perfect Server &#8211; Ubuntu 18.04 (Bionic Beaver) with Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot and ISPConfig 3.1<\/a><\/p>\n<p>You can stop after the installation and configuration of Apache2.<\/p>\n<h2 id=\"step-download-vmailpanel\">Step 1: Download vMailpanel<\/h2>\n<p>Download the vMailpanel package:<\/p>\n<p class=\"command\">cd \/usr\/share<\/p>\n<p>Get the latest version of vMailpanel:<\/p>\n<p class=\"command\">git clone https:\/\/git.com\/wolmfan68\/vMailpanel<\/p>\n<p>OK, now we can start.<\/p>\n<h2 id=\"step-install-and-configure-openldap\">Step 2: Install and configure OpenLDAP<\/h2>\n<p>Install OpenLDAP and ldap-utils:<\/p>\n<p class=\"command\">apt -y install slapd ldap-utils php-ldap<\/p>\n<p>Reconfigure slapd to make sure it reflects your wanted setup<\/p>\n<p class=\"command\">dpkg-reconfigure slapd<\/p>\n<p>You will have to answer some questions:<\/p>\n<pre>Omit OpenLDAP server configuration? No<\/pre>\n<pre> DNS domain name: example.tld <span class=\"highlight\">==&gt;put your domain name here<\/span><\/pre>\n<pre>Organization name: example.tld <span class=\"highlight\">==&gt; put your organization here<\/span><\/pre>\n<pre> Administrator password: secret <span class=\"highlight\">==&gt; put your password<\/span><\/pre>\n<pre> Confirm password: secret <\/pre>\n<pre>Database backend to use: MDB<\/pre>\n<pre> Do you want the database to be removed when slapd is purged? Yes<\/pre>\n<pre> Move old database? Yes<\/pre>\n<p>Change into the \/etc\/ldap\/schema directory:<\/p>\n<p class=\"command\">cd \/etc\/ldap\/schema<\/p>\n<p>Copy the phamm.schema and perversia.net.schema from the phamm package to the schema directory:<\/p>\n<p class=\"command\">cp \/usr\/share\/vMailbox\/schema\/* \/etc\/ldap\/schema.<\/p>\n<p>Now we add the schemas to openldap.<\/p>\n<p class=\"command\">ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/ldap\/schema\/phamm.ldif<span>\u00a0<\/span><br \/>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/ldap\/schema\/ISPEnv2.ldif<br \/>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/ldap\/schema\/amavis.ldif<span>\u00a0<\/span><br \/>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/ldap\/schema\/pureftpd.ldif<span>\u00a0<\/span><br \/>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/ldap\/schema\/perversia.net.ldif<\/p>\n<p>Now we create the o=hosting entry, and the vmail account.<\/p>\n<p>Modify the text below to your needs and wants and generate a password for the vmail account. The hash currently in this file sets the password to read-only<\/p>\n<p>To create the hash for the vmail account\u00a0 issue the following command:<\/p>\n<p class=\"command\">slappasswd -h {MD5}<\/p>\n<p>Type the wanted password twice and copy the result into the text below.<\/p>\n<p class=\"command\">nano base.ldif<\/p>\n<p>Contents of base.ldif<\/p>\n<pre>dn: o=hosting,dc=example,dc=tld<\/pre>\n<pre>objectClass: organization<\/pre>\n<pre>objectClass: top<\/pre>\n<pre>o: hosting description: Hosting Organization<\/pre>\n<pre># Read only account<\/pre>\n<pre>dn: cn=vmail,o=hosting,dc=example,dc=tld<\/pre>\n<pre>objectClass: simpleSecurityObject<\/pre>\n<pre>objectClass: organizationalRole<\/pre>\n<pre>cn: vmail<\/pre>\n<pre>userPassword: {MD5}M267sheb6qc0Ck8WIPOvQA==<\/pre>\n<pre>description: Read only account<\/pre>\n<p>Load the base dn into the database with the following command:<\/p>\n<p class=\"command\">ldapmodify -a -D cn=admin,dc=example,dc=tld -W -f base.ldif<\/p>\n<p>Now we need to modify the acl&#8217;s so that the correct access is given to each user type.<\/p>\n<p class=\"command\">ldapmodify -Y EXTERNAL -H ldapi:\/\/\/ -f acl-remove.ldif<\/p>\n<p class=\"command\">ldapmodify -Y EXTERNAL -H ldapi:\/\/\/ -f acl-new.ldif<\/p>\n<p>You can check the new acl&#8217;s with the following command:<\/p>\n<p class=\"command\">slapcat -n 0<\/p>\n<p>This concludes the OpenLDAP configuration.<\/p>\n<h2 id=\"step-install-and-configure-postfix\">Step 3: Install And Configure Postfix<\/h2>\n<p>Before this, we need to have the<span>\u00a0<\/span><span class=\"system\">vmail<\/span><span>\u00a0<\/span>user and its home directory.<\/p>\n<p>Create the<span>\u00a0<\/span><span class=\"system\">vmail<\/span><span>\u00a0<\/span>user and group:<\/p>\n<p class=\"command\">useradd vmail<\/p>\n<p>By default, the group<span>\u00a0<\/span><span class=\"system\">vmail<\/span><span>\u00a0<\/span>is created, too.<\/p>\n<p>Check<span>\u00a0<\/span><span class=\"system\">\/etc\/passwd<\/span><span>\u00a0<\/span>for the actual uid and group number.<\/p>\n<p>Next, create the<span>\u00a0<\/span><span class=\"system\">vmail<\/span><span>\u00a0<\/span>directory and set ownership to the<span>\u00a0<\/span><span class=\"system\">vmail<\/span><span>\u00a0<\/span>user and group.<\/p>\n<p class=\"command\">mkdir \/home\/vmail<br \/>mkdir \/home\/vmail\/domains<span>\u00a0<\/span><br \/>chown -R vmail:vmail \/home\/vmail<\/p>\n<p>Run the following command to install Postfix and other required applications:<\/p>\n<p class=\"command\">apt install postfix postfix-ldap<\/p>\n<p>You will be asked two questions. Answer as follows:<\/p>\n<p><span class=\"system\">General type of mail configuration:<\/span><span>\u00a0<\/span><span class=\"highlight\">&lt;&#8211;Stand alone<\/span><br \/><span class=\"system\">System mail name:<\/span><span>\u00a0<\/span><span class=\"highlight\">&lt;&#8211; mail.example.tld<\/span><\/p>\n<p>We do not install sasl since we will use the Dovecot LDA and deliver.<\/p>\n<p>Now we create the certificates for TLS:<\/p>\n<p class=\"command\">mkdir \/etc\/postfix\/ssl<br \/>cd \/etc\/postfix\/ssl\/<br \/>openssl genrsa -des3 -rand \/etc\/hosts -out smtpd.key 1024<\/p>\n<p class=\"command\">chmod 600 smtpd.key<br \/>openssl req -new -key smtpd.key -out smtpd.csr<\/p>\n<p class=\"command\">openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt<\/p>\n<p class=\"command\">openssl rsa -in smtpd.key -out smtpd.key.unencrypted<\/p>\n<p class=\"command\">mv -f smtpd.key.unencrypted smtpd.key<br \/>openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650<\/p>\n<p>Note: you can copy all of the files under examples\/postfix to your etc\/postfix directory and make changes accordingly. For completeness reasons I will give the complete setup below.<\/p>\n<p>Now we will configure postfix:<\/p>\n<p class=\"command\">cd \/etc\/postfix<span>\u00a0<\/span><\/p>\n<p class=\"command\">mv \/etc\/postfix\/main.cf \/etc\/postfix\/main.cf.bck<\/p>\n<p class=\"command\">nano \/etc\/postfix\/main.cf<\/p>\n<p>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, &#8230;) to the respective aliases if they are configured.<\/p>\n<p><span class=\"system\">smtpd_banner = $myhostname ESMTP $mail_name<br \/>biff = no<br \/>\u00a0<br \/># appending .domain is the MUA&#8217;s job.<br \/>append_dot_mydomain = no<br \/>\u00a0<br \/># Uncomment the next line to generate &#8220;delayed mail&#8221; warnings<br \/>delay_warning_time = 4h<br \/>\u00a0<br \/># TLS parameters<br \/>smtpd_tls_cert_file = \/etc\/postfix\/ssl\/smtpd.crt<br \/>smtpd_tls_key_file = \/etc\/postfix\/ssl\/smtpd.key<br \/>smtpd_use_tls = yes<br \/>smtpd_tls_session_cache_database = btree:${queue_directory}\/smtpd_scache<br \/>smtp_tls_session_cache_database = btree:${queue_directory}\/smtp_scache<br \/>\u00a0<br \/>myhostname = mail.example.tld<br \/>alias_maps = hash:\/etc\/aliases,<br \/>alias_database = hash:\/etc\/aliases<br \/>myorigin = localhost<br \/>relayhost =<span>\u00a0<\/span><br \/>mynetworks = 127.0.0.0\/8<br \/>dovecot_destination_recipient_limit = 1<br \/>mailbox_command = \/usr\/lib\/deliver<br \/>mailbox_size_limit = 0<br \/>recipient_delimiter = +<br \/>inet_interfaces = all<br \/>inet_protocols = all<br \/>#smtp_bind_address = your ip address (optional) ==&gt;unmark and change the ip address for your setup.<br \/>smtpd_sasl_local_domain =<span>\u00a0<\/span><br \/>smtpd_sasl_auth_enable = yes<br \/>smtpd_sasl_security_options = noanonymous<br \/>smtpd_sasl_type = dovecot<br \/>smtpd_sasl_path = private\/auth<br \/>broken_sasl_auth_clients = yes<br \/>smtpd_tls_auth_only = no<\/span><\/p>\n<p>smtp_use_tls = yes<br \/>smtp_tls_note_starttls_offer = yes<br \/>smtpd_tls_CAfile = \/etc\/postfix\/ssl\/cacert.pem<br \/>smtpd_tls_loglevel = 1<br \/>smtpd_tls_received_header = yes<br \/>smtpd_tls_session_cache_timeout = 3600s<br \/>tls_random_source = dev:\/dev\/urandom<\/p>\n<p>home_mailbox = Maildir\/<br \/>\u00a0<br \/>smtpd_recipient_restrictions =<br \/>\u00a0\u00a0\u00a0 permit_mynetworks<br \/>\u00a0\u00a0\u00a0 permit_sasl_authenticated<br \/>\u00a0\u00a0\u00a0 reject_invalid_hostname<br \/>\u00a0\u00a0\u00a0 reject_non_fqdn_hostname<br \/>\u00a0\u00a0\u00a0 reject_non_fqdn_sender<br \/>\u00a0\u00a0\u00a0 reject_non_fqdn_recipient<br \/>\u00a0\u00a0\u00a0 reject_unauth_destination<br \/>\u00a0\u00a0\u00a0 reject_unauth_pipelining<br \/>\u00a0\u00a0\u00a0 reject_invalid_hostname<br \/>\u00a0\u00a0\u00a0 reject_unknown_sender_domain<br \/>\u00a0\u00a0\u00a0 reject_rbl_client list.dsbl.org<br \/>\u00a0\u00a0\u00a0 reject_rbl_client cbl.abuseat.org<br \/>\u00a0\u00a0\u00a0 reject_rhsbl_sender dsn.fc-ignorant.org<\/p>\n<p>smtpd_data_restrictions =<br \/>\u00a0\u00a0\u00a0 reject_unauth_pipelining,<br \/>\u00a0\u00a0\u00a0 reject_multi_recipient_bounce,<br \/>\u00a0\u00a0\u00a0 permit<\/p>\n<p>smtpd_helo_required = yes<br \/>\u00a0<br \/># transport_maps<br \/>maildrop_destination_concurrency_limit = 2<span>\u00a0<\/span><br \/>maildrop_destination_recipient_limit = 1<br \/>gnarwl_destination_concurrency_limit = 1<span>\u00a0<\/span><br \/>gnarwl_destination_recipient_limit = 1<br \/>transport_maps = hash:\/etc\/postfix\/transport, ldap:\/etc\/postfix\/ldap-transport.cf<br \/>mydestination = $transport_maps, localhost, localhost.localdomain, $myhostname, localhost.$mydomain, $mydomain<\/p>\n<p>virtual_alias_maps =<span>\u00a0<\/span><br \/>\u00a0\u00a0\u00a0 ldap:\/etc\/postfix\/ldap-aliases.cf,<br \/>\u00a0\u00a0\u00a0 ldap:\/etc\/postfix\/ldap-virtualforward.cf,<br \/>\u00a0\u00a0\u00a0 ldap:\/etc\/postfix\/ldap-accountsmap.cf<br \/>\u00a0<br \/># virtual accounts for delivery<br \/>virtual_mailbox_base = \/home\/vmail<br \/>virtual_mailbox_maps =<br \/>\u00a0\u00a0\u00a0 ldap:\/etc\/postfix\/ldap-accounts.cf<br \/>virtual_minimum_uid = 1000 <span class=\"highlight\">==&gt;\u00a0Change this to the actual uid of the user vmail<\/span><br \/>virtual_uid_maps = static:1000\u00a0<span class=\"highlight\">==&gt;\u00a0Change this to the actual uid of the user vmail<\/span><br \/>virtual_gid_maps = static:1000\u00a0<span class=\"highlight\">==&gt;\u00a0Change this to the actual uid of the user vmail<\/span><br \/>\u00a0<br \/>local_recipient_maps = $alias_maps<\/p>\n<p>recipient_bcc_maps = ldap:\/etc\/postfix\/ldap-vacation.cf<span\/><\/p>\n<p class=\"command\">nano \/etc\/postfix\/master.cf<\/p>\n<p>And paste the following into it (add the end):<\/p>\n<pre>d<span class=\"system\">ovecot unix - n n - - pipe&#13; \u00a0\u00a0\u00a0\u00a0 flags=DRhu user=vmail:vmail argv=\/usr\/lib\/dovecot\/deliver -f ${sender} -d ${recipient}&#13;\ngnarwl unix - n n - - pipe&#13; \u00a0 \u00a0 flags=F user=vmail argv=\/usr\/bin\/gnarwl -a ${user}@${nexthop} -s ${sender}<\/span><\/pre>\n<p>\u00a0Now we need to write the different ldap-xxx.cf files<\/p>\n<p class=\"command\">nano ldap-accounts.cf<\/p>\n<p>And paste the following in to it:<\/p>\n<p><span class=\"system\">server_host = localhost<br \/>server_port = 389<br \/>version = 3<br \/>bind = yes<br \/>start_tls = no<br \/>bind_dn = cn=vmail,o=hosting,dc=example,dc=tld<br \/>bind_pw = readmonly<br \/>search_base = o=hosting,dc=example,dc=tld<br \/>scope = sub<br \/>query_filter = (&amp;(&amp;(objectClass=VirtualMailAccount)(mail=%s))(forwardActive=FALSE)(accountActive=TRUE)(delete=FALSE))<br \/>result_attribute = mailbox<span>\u00a0<\/span><\/span><\/p>\n<p class=\"command\">nano ldap-accounstmap.cf<\/p>\n<p>And paste the following in to it:<\/p>\n<p><span class=\"system\">server_host = localhost<br \/>server_port = 389<br \/>version = 3<br \/>bind = yes<br \/>start_tls = no<br \/>bind_dn = cn=vmail,o=hosting,dc=example,dc=tld<br \/>bind_pw = readonly<br \/>search_base = o=hosting,dc=example,dc=tld<br \/>scope = sub<br \/>query_filter = (&amp;(&amp;(objectClass=VirtualMailAccount)(mail=%s))(forwardActive=FALSE)(accountActive=TRUE)(delete=FALSE))<br \/>result_attribute = mail<span>\u00a0<\/span><\/span><\/p>\n<p class=\"command\">nano ldap-aliases.cf<\/p>\n<p>And paste the following in to it:<\/p>\n<p><span class=\"system\">server_host = localhost<br \/>server_port = 389<br \/>version = 3<br \/>bind = yes<br \/>start_tls = no<br \/>bind_dn = cn=vmail,o=hosting,dc=example,dc=tld<br \/>bind_pw = readonly<br \/>search_base = o=hosting,dc=example,dc=tld<br \/>scope = sub<br \/>query_filter = (&amp;(&amp;(objectClass=VirtualMailAlias)(mail=%s))(accountActive=TRUE))<br \/>result_attribute = maildrop<span>\u00a0<\/span><\/span><\/p>\n<p class=\"command\">nano ldap-transport.cf<\/p>\n<p>And paste the following in to it:<\/p>\n<p><span class=\"system\">server_host = localhost<br \/>server_port = 389<br \/>version = 3<br \/>bind = yes<br \/>start_tls = no<br \/>bind_dn = cn=vmail,o=hosting,dc=example,dc=tld<br \/>bind_pw = readonly<br \/>search_base = o=hosting,dc=example,dc=tld<br \/>scope = sub<br \/>query_filter = (&amp;(&amp;(vd=%s)(objectClass=VirtualDomain))(accountActive=TRUE)(delete=FALSE))<span>\u00a0<\/span><br \/>result_attribute = postfixTransport<span>\u00a0<\/span><\/span><\/p>\n<p>nano ldap-vacation.cf<\/p>\n<p>And paste the following in to it:<\/p>\n<p><span class=\"system\">server_host = localhost<br \/>server_port = 389<br \/>version = 3<br \/>bind = yes<br \/>start_tls = no<br \/>bind_dn = cn=vmail,o=hosting,dc=example,dc=tld<br \/>bind_pw = readonly<br \/>search_base = o=hosting,dc=example,dc=tld<br \/>scope = sub<br \/>query_filter = (&amp;(&amp;(objectClass=VirtualMailAccount)(mail=%s))(vacationActive=TRUE)(forwardActive=FALSE)(accountActive=TRUE)(delete=FALSE))<br \/>result_attribute = mailAutoreply<span>\u00a0<\/span><\/span><\/p>\n<p>nano ldap-virtualforward.cf<\/p>\n<p>And paste the following in to it:<\/p>\n<p><span class=\"system\">server_host = localhost<br \/>server_port = 389<br \/>version = 3<br \/>bind = yes<br \/>start_tls = no<br \/>bind_dn = cn=vmail,o=hosting,dc=example,dc=tld<br \/>bind_pw = readonly<br \/>search_base = o=hosting,dc=example,dc=tld<br \/>scope = sub<br \/>query_filter = (&amp;(&amp;(objectClass=VirtualMailAccount)(mail=%s))(vacationActive=FALSE)(forwardActive=TRUE)(accountActive=TRUE)(delete=FALSE))<br \/>result_attribute = maildrop<\/span><\/p>\n<p>This concludes the postfix setup.<span>\u00a0<\/span><\/p>\n<h2 id=\"step-install-and-configure-dovecot\">Step 4: Install And Configure Dovecot<\/h2>\n<p class=\"command\">apt install dovecot-imapd dovecot-pop3d dovecot-ldap<\/p>\n<p>This will install dovecot and all necessary files and also create the standard SSL certificates for IMAPs and POP3s.<\/p>\n<p>First, we change into the dovecot directory.<\/p>\n<p><span>Note: you can copy all of the files under examples\/dovecot to your etc\/dovecot directory and make changes accordingly. For completeness reasons I will give the complete setup below.<\/span><\/p>\n<p class=\"command\">\u00a0cd \/etc\/dovecot<\/p>\n<p>Now we configure the different dovecot configuration files.<\/p>\n<p class=\"command\">nano dovecot-ldap.conf.ext<\/p>\n<p>\u00a0And make the following changes:<\/p>\n<p><span class=\"system\">hosts\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = localhost:389<br \/>ldap_version\u00a0\u00a0\u00a0 = 3<br \/>auth_bind\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = yes<br \/>dn\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = cn=vmail,o=hosting,dc=example,dc=tld<br \/>dnpass\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = readonly<br \/>base\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = o=hosting,dc=hosting,dc=tld<br \/>scope\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = subtree<br \/>deref\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = never<\/span><\/p>\n<p>user_attrs = quota=quota=maildir:storage<br \/>user_attrs = quota=quota=maildir:storage=%$B<br \/>user_filter = (&amp;(objectClass=VirtualMailAccount)(accountActive=TRUE)(mail=%u))<br \/>pass_attrs = mail,userPassword<br \/>pass_filter = (&amp;(objectClass=VirtualMailAccount)(accountActive=TRUE)(mail=%u))<br \/>default_pass_scheme = MD5<\/p>\n<p class=\"command\">cd conf.d<\/p>\n<p class=\"command\">vi 10-auth.conf<\/p>\n<p>\u00a0And change the section<span>\u00a0<\/span><span class=\"system\">Password and User Databases<span>\u00a0<\/span><\/span>to this:<\/p>\n<p><span class=\"system\">#!include auth-deny.conf.ext<br \/>#!include auth-master.conf.ext<\/span><\/p>\n<p>#!include auth-system.conf.ext<br \/>#!include auth-sql.conf.ext<br \/>!include auth-ldap.conf.ext<br \/>#!include auth-passwdfile.conf.ext<br \/>#!include auth-checkpassword.conf.ext<br \/>#!include auth-vpopmail.conf.ext<br \/>#!include auth-static.conf.ext<\/p>\n<p class=\"command\">vi 10-mail.conf<span>\u00a0<\/span><\/p>\n<p>\u00a0And make the following changes:<\/p>\n<p><span class=\"system\">mail_location = maildir:\/home\/vmail\/%d\/%u<\/span><\/p>\n<p><span class=\"system\">mail_uid = 1000 <span class=\"highlight\">==&gt; change to the actual vmail uid value<\/span><\/span><\/p>\n<p><span class=\"system\">mail_gid = 1000 <span class=\"highlight\">==&gt; change this to the actual vmail gid value<\/span><\/span><\/p>\n<p><span class=\"system\">first_valid_uid = 1000\u00a0<span class=\"highlight\">==&gt; change to the actual vmail uid value<\/span><\/span><\/p>\n<p><span class=\"system\">first_valid_gid = 1000\u00a0<\/span><span class=\"highlight\">==&gt; change this to the actual vmail gid value<\/span><\/p>\n<p class=\"command\">vi 10-master.conf<span>\u00a0<\/span><\/p>\n<p>And make the following changes:<\/p>\n<p>\u00a0<span class=\"system\">\u00a0 unix_listener auth-userdb {<br \/>\u00a0\u00a0\u00a0 mode = 0666<br \/>\u00a0\u00a0\u00a0 user = vmail<br \/>\u00a0\u00a0\u00a0 group = vmail<br \/>\u00a0 }<\/span><\/p>\n<p>\u00a0 # Postfix smtp-auth<br \/>\u00a0 unix_listener \/var\/spool\/postfix\/private\/auth {<br \/>\u00a0\u00a0\u00a0 mode = 0666<br \/>\u00a0 }<\/p>\n<p class=\"command\">\u00a0vi 15-lda.conf<\/p>\n<p>And make the following changes:<span>\u00a0<\/span><\/p>\n<p><span class=\"system\">postmaster_address =<span>\u00a0<\/span><a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"8afae5f9fee7ebf9feeff8caeff2ebe7fae6efa4fee6ee\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a><\/span><\/p>\n<p><span class=\"system\">lda_mailbox_autocreate = yes<\/span><\/p>\n<p>This concludes the Dovecot configuration.<\/p>\n<h2 id=\"step-install-and-configure-gnarwl\">Step 5: Install And Configure gnarwl<\/h2>\n<p>Let&#8217;s install gnarwl:<\/p>\n<p class=\"command\">apt install gnarwl<\/p>\n<p>Now let&#8217;s configure gnarwl.<\/p>\n<p>First, we&#8217;re going to back up the original configuration file and replace it with a new one.<\/p>\n<p class=\"command\">mv \/etc\/gnarwl.conf \/etc\/gnarwl.conf.bck<\/p>\n<p>Now we create the new conf file:<\/p>\n<p class=\"command\">vi \/etc\/gnarwl.conf<\/p>\n<p>And insert the following:<\/p>\n<pre>map_sender $sender&#13;\nmap_receiver $recepient&#13;\nmap_subject $subject&#13;\nmap_field $begin vacationStart&#13;\nmap_field $end vacationEnd&#13;\nmap_field $fullname cn&#13;\nmap_field $deputy vacationForward&#13;\nmap_field $reply mail&#13;\nserver localhost&#13;\nport 389&#13;\nscope sub&#13;\nlogin cn=vmail,o=hosting,dc=example,dc=tld&#13;\npassword readonly&#13;\nprotocol 0&#13;\nbase dc=example,dc=tld&#13;\nqueryfilter (&amp;(mailAutoreply=$recepient)(vacationActive=TRUE))&#13;\nresult vacationInfo&#13;\nblockfiles \/var\/lib\/gnarwl\/block\/&#13;\numask 0644&#13;\nblockexpire 48&#13;\nmta \/usr\/sbin\/sendmail -F $recepient -t $sender&#13;\nmaxreceivers 64&#13;\nmaxheader 512&#13;\ncharset ISO8859-1&#13;\nbadheaders \/var\/lib\/gnarwl\/badheaders.db&#13;\nblacklist \/var\/lib\/gnarwl\/blacklist.db&#13;\nforceheader \/var\/lib\/gnarwl\/header.txt&#13;\nforcefooter \/var\/lib\/gnarwl\/footer.txt&#13;\nrecvheader To Cc&#13;\nloglevel 3<\/pre>\n<p><span>Make the gnarwl directory readable for the vmail user<\/span><\/p>\n<p class=\"command\">chown -R vmail:vmail \/var\/lib\/gnarwl\/<\/p>\n<p>Next, we need to add the gnarwl transport to postfix<\/p>\n<p class=\"command\">vi \/etc\/postfix\/transport<\/p>\n<p>Insert the following:<\/p>\n<p class=\"system\">.autoreply\u00a0\u00a0\u00a0\u00a0\u00a0 gnarwl:<\/p>\n<p>Now we need to create the transport.db<\/p>\n<p class=\"command\">postmap \/etc\/postfix\/transport<\/p>\n<p>This concludes the gnarwl configuration.<span>\u00a0<\/span><\/p>\n<h2 id=\"step-install-and-configure-phamm\">Step 6: Install And Configure vMailpanel<\/h2>\n<p>Since we downloaded\u00a0vMailpanel before, we can directly begin with the configuration of the vMailpanel interface.<\/p>\n<p class=\"command\">chown -R www-data:www-data \/usr\/share\/phamm<br \/>cd \/usr\/share\/vMailpanel<\/p>\n<p>Now we will configure phamm for actual use.<\/p>\n<p class=\"command\">cp config.inc.example.php config.inc.php<\/p>\n<p class=\"command\">nano config.inc.php<\/p>\n<p>Change the ldap connection parameters to fit your actual configuration.<\/p>\n<pre>\/\/ *============================*&#13;\n\/\/ *=== LDAP Server Settings ===*&#13;\n\/\/ *============================*&#13;\n&#13;\n\/\/ The server address (IP or FQDN)&#13;\ndefine ('LDAP_HOST_NAME','127.0.0.1');&#13;\n&#13;\n\/\/ The protocol version [2,3]&#13;\ndefine ('LDAP_PROTOCOL_VERSION','3');&#13;\n&#13;\n\/\/ The server port&#13;\ndefine ('LDAP_PORT','389');&#13;\n&#13;\n\/\/ The container&#13;\ndefine ('SUFFIX','dc=example,dc=tld');&#13;\n&#13;\n\/\/ The admin bind dn (could be rootdn)&#13;\ndefine ('BINDDN','cn=admin,dc=example,dc=tld');&#13;\n&#13;\n\/\/ The Phamm container&#13;\ndefine ('LDAP_BASE','o=hosting,dc=example,dc=tld');<\/pre>\n<p>and change<\/p>\n<pre>\/\/ Welcome message&#13;\ndefine ('SEND_WELCOME',1);&#13;\n$welcome_msg = '..\/welcome_message.txt';&#13;\n$welcome_subject = 'Welcome!';&#13;\n# $welcome_sender = '<a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"4838273b3c25293b3c2d3a0824272b292420273b3c\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a>';&#13;\n$welcome_bcc = '<a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"04746b777069657770617644617c65697468612a706860\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a>';<\/pre>\n<p>This will send a welcome message and a bcc to your postmaster account.<\/p>\n<p>Enable the fpt and person plugin by removing the \/\/ in the plugins section. If wanted you can also enable the davical and or jabber plugins, the schema needed for these plugins is installed.<\/p>\n<p>In the config.inc.php you will find:<\/p>\n<pre><span>define ('DELETE_ACCOUNT_IMMEDIATELY', false);<br\/><\/span><\/pre>\n<p><span>If you set this to true, account or domain deletion takes effect immediately. However, the physical mailbox is not deleted (or the domain directory). In order to delete the physical mailbox, we should use the cleaner.sh script. This is described below.<\/span><\/p>\n<p>You can edit<span>\u00a0<\/span><span class=\"system\">plugins\/mail.xml<\/span><span>\u00a0<\/span>to change the defaults for SMTP and quota, modify them to your needs. The default is set to 1GB quota.<\/p>\n<p><span>You can edit<span>\u00a0<\/span><\/span><span class=\"system\">plugins\/ftp.xml<\/span><span><span>\u00a0<\/span>to change the defaults for default ftp (base) directory and quota, modify them to your needs.<\/span><\/p>\n<p>Do not forget to create the aliases and or mailboxes for postmaster, webmaster since these are used by official&#8217;s and ISP&#8217;s to send mail to in case of &#8230; Not having these addresses could result in being blacklisted.<\/p>\n<p>By default the aliases <a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection#7716150204123713181a161e1959031b13\" target=\"_blank\" rel=\"noopener\"><span class=\"__cf_email__\" data-cfemail=\"5f3e3d2a2c3a1f3b30323e3631712b333b\">[email\u00a0protected]<\/span><\/a>\u00a0and <a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection#0a797a6b674a6e65676b6364247e666e\" target=\"_blank\" rel=\"noopener\"><span class=\"__cf_email__\" data-cfemail=\"90e3e0f1fdd0f4fffdf1f9febee4fcf4\">[email\u00a0protected]<\/span><\/a>\u00a0that default to <a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection#81f1eef2f5ece0f2f5e4f3c1e5eeece0e8efaff5ede5\" target=\"_blank\" rel=\"noopener\"><span class=\"__cf_email__\" data-cfemail=\"fa8a95898e979b898e9f88ba9e95979b9394d48e969e\">[email\u00a0protected]<\/span><\/a>\u00a0are created.<\/p>\n<p>Now the cleaner script:<\/p>\n<p class=\"command\">cp tools\/cleaner.sh \/home\/vmail\/cleaner.sh<\/p>\n<p>Change the following in cleaner.sh<\/p>\n<pre>BINDDN=\"cn=admin,dc=example,dc=tld\"<br\/>BINDPW=\"password\"<br\/>LDAP_BASE=\"o=hosting,dc=example,dc=tld\"<\/pre>\n<p>To reflect your installation<\/p>\n<p class=\"command\">nano \/home\/vmail\/cleaner.sh<\/p>\n<p class=\"command\">crontab -e<\/p>\n<p>Insert the following:<\/p>\n<pre>*\/10 * * * * \/home\/vmail\/cleaner.sh<\/pre>\n<p>This will run the cleaner script every 10 minutes. Feel free to change the timing.<\/p>\n<p>Now we will add vMailpanel to Apache<\/p>\n<p class=\"command\">nano \/etc\/apache2\/conf-enabled\/000-default.conf<\/p>\n<p>And add between the &lt;VirtualHost&gt; &lt;\/VirtualHost&gt; entries the following:<\/p>\n<pre>Alias \/vmailpanel \/usr\/share\/vMailpanel\/public<\/pre>\n<p>This concludes the vMailpanel configuration.<\/p>\n<h2 id=\"step-install-and-configure-roundcube-webmail-\">Step 7: Install and configure Roundcube webmail<\/h2>\n<p>First, we create a database called<span>\u00a0<\/span><span class=\"system\">roundcube<\/span>:<\/p>\n<p class=\"command\">mysqladmin -u root -p create roundcube<\/p>\n<p>Next, we go to the MySQL shell:<\/p>\n<p class=\"command\">mysql -u root -p<\/p>\n<p>On the MySQL shell, we create the user<span>\u00a0<\/span><span class=\"system\">roundcube<\/span><span>\u00a0<\/span>with the password<span>\u00a0<\/span><span class=\"system\">roundcube_password<\/span><span>\u00a0<\/span>(replace it with a password of your choice) who has<span>\u00a0<\/span><span class=\"system\">SELECT,INSERT,UPDATE,DELETE<\/span><span>\u00a0<\/span>privileges on the<span>\u00a0<\/span><span class=\"system\">roundcube<\/span><span>\u00a0<\/span>database. This user will be used by Postfix and Courier to connect to the<span>\u00a0<\/span><span class=\"system\">roundcube<\/span><span>\u00a0<\/span>database:<\/p>\n<p class=\"command\">GRANT SELECT, INSERT, UPDATE, DELETE ON roundcube.* TO &#8217;roundcube&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8217;roundcube_password&#8217;;<br \/>GRANT SELECT, INSERT, UPDATE, DELETE ON roundcube.* TO &#8217;roundcube&#8217;@&#8217;localhost.localdomain&#8217; IDENTIFIED BY &#8217;roundcube_password&#8217;;<br \/>FLUSH PRIVILEGES;<\/p>\n<p>Now we download and install Roundcube:<\/p>\n<p class=\"command\">cd\/usr\/src<span>\u00a0<\/span><br \/>wget https:\/\/github.com\/roundcube\/roundcubemail\/releases\/download\/1.3.6\/roundcubemail-1.3.6.tar.gz<\/p>\n<p class=\"command\">tar xvzf roundcubemail-1.3.6.tar.gz<\/p>\n<p class=\"command\">mv roundcubemail-1.3.6 \/var\/www\/roundcube<\/p>\n<p class=\"command\">chown -R www-data:www-data \/var\/www\/roundcube<\/p>\n<p class=\"command\">cd \/var\/www\/roundcube<\/p>\n<p>Always check for the lastest version of Roundcube and download that one and modify the commands above to the version of Roundcube you downloaded.<\/p>\n<p><a href=\"https:\/\/roundcube.net\/download\" target=\"_blank\" rel=\"noopener\">https:\/\/roundcube.net\/download\/<\/a><\/p>\n<p>Now we load the sql tables in to the database we created before:<\/p>\n<p class=\"command\">mysql -u roundcube -p roundcube &lt;\u00a0 SQL\/mysql.initial.sql<\/p>\n<p>Now we edit the Roundcube configuration:<\/p>\n<p class=\"command\">cp config\/config.inc.php.sample config\/config.inc.php<\/p>\n<p>Set the database configuration:<\/p>\n<p class=\"command\">nano config\/config.inc.php<\/p>\n<p>Change the following line to the database configuration:<\/p>\n<pre>$rcmail_config['db_dsnw'] = 'mysql:\/\/roundcube:<a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"9eecf1ebf0fafdebfcfbc1eeffedede9f1ecfadef2f1fdfff2f6f1edea\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a>\/roundcube';<\/pre>\n<p>And change the following<\/p>\n<p>From:<\/p>\n<pre>\/\/ List of active plugins (in plugins\/ directory)&#13;\n$config['plugins'] = array(<\/pre>\n<pre> 'archive', <\/pre>\n<pre> 'zipdownload',<\/pre>\n<p>To:<\/p>\n<pre>\/\/ List of active plugins (in plugins\/ directory)&#13;\n$config['plugins'] = array(<\/pre>\n<pre> 'archive', <\/pre>\n<pre> 'zipdownload',<\/pre>\n<pre> 'password',<\/pre>\n<pre> 'vacation', <\/pre>\n<p><span>Change:<\/span><\/p>\n<pre>chars.$rcmail_config['des_key'] = 'rcmail-!24ByteDESkey*Str';<\/pre>\n<p>To:<\/p>\n<pre>chars.$rcmail_config['des_key'] = '<span class=\"highlight\">your-own-24-digitkeystring<\/span>';<\/pre>\n<p>Change:<\/p>\n<pre>$rcmail_config['default_host'] = '';<\/pre>\n<p>To:<\/p>\n<pre>$rcmail_config['default_host'] = 'localhost'; <\/pre>\n<p>Change:<\/p>\n<pre>$rcmail_config['smtp_server'] = ''; <\/pre>\n<p>To<\/p>\n<pre>$rcmail_config['smtp_server'] = 'localhost'; <\/pre>\n<p>The configuration for the password plugin:<\/p>\n<p class=\"command\">cp plugins\/password\/config.inc.php.dist plugins\/password\/config.inc.php<\/p>\n<p>Edit the configuration:<\/p>\n<p class=\"command\">nano\u00a0plugins\/password\/config.inc.php<\/p>\n<p>Change the following entries<\/p>\n<p>From:<\/p>\n<pre>$rcmail_config['password_driver'] = 'sql';<\/pre>\n<p>To:<\/p>\n<pre>$rcmail_config['password_driver'] = 'ldap'; <\/pre>\n<p>From:<\/p>\n<pre>\/\/ LDAP Driver options&#13;\n\/\/ -------------------&#13;\n\/\/ LDAP server name to connect to.&#13;\n\/\/ You can provide one or several hosts in an array in which case the hosts are tried from left to right.&#13;\n\/\/ Exemple: array('ldap1.exemple.com', 'ldap2.exemple.com');&#13;\n\/\/ Default: 'localhost'&#13;\n$rcmail_config['password_ldap_host'] = 'localhost';&#13;\n&#13;\n\/\/ LDAP server port to connect to&#13;\n\/\/ Default: '389'&#13;\n$rcmail_config['password_ldap_port'] = '389';&#13;\n&#13;\n\/\/ TLS is started after connecting&#13;\n\/\/ Using TLS for password modification is recommanded.&#13;\n\/\/ Default: false&#13;\n$rcmail_config['password_ldap_starttls'] = false;&#13;\n&#13;\n\/\/ LDAP version&#13;\n\/\/ Default: '3'&#13;\n$rcmail_config['password_ldap_version'] = '3';&#13;\n&#13;\n\/\/ LDAP base name (root directory)&#13;\n\/\/ Exemple: 'dc=exemple,dc=com'&#13;\n$rcmail_config['password_ldap_basedn'] = 'dc=exemple,dc=com';&#13;\n&#13;\n\/\/ LDAP connection method&#13;\n\/\/ There is two connection method for changing a user's LDAP password.&#13;\n\/\/ 'user': use user credential (recommanded, require password_confirm_current=true)&#13;\n\/\/ 'admin': use admin credential (this mode require password_ldap_adminDN and password_ldap_adminPW)&#13;\n\/\/ Default: 'user'&#13;\n$rcmail_config['password_ldap_method'] = 'user';&#13;\n&#13;\n\/\/ LDAP Admin DN&#13;\n\/\/ Used only in admin connection mode&#13;\n\/\/ Default: null&#13;\n$rcmail_config['password_ldap_adminDN'] = null;&#13;\n&#13;\n\/\/ LDAP Admin Password&#13;\n\/\/ Used only in admin connection mode&#13;\n\/\/ Default: null&#13;\n$rcmail_config['password_ldap_adminPW'] = null;&#13;\n&#13;\n\/\/ LDAP user DN mask&#13;\n\/\/ The user's DN is mandatory and as we only have his login,&#13;\n\/\/ we need to re-create his DN using a mask&#13;\n\/\/ '%login' will be replaced by the current roundcube user's login&#13;\n\/\/ '%name' will be replaced by the current roundcube user's name part&#13;\n\/\/ '%domain' will be replaced by the current roundcube user's domain part&#13;\n\/\/ Exemple: 'uid=%login,ou=people,dc=exemple,dc=com'&#13;\n$rcmail_config['password_ldap_userDN_mask'] = 'uid=%login,ou=people,dc=exemple,dc=com';&#13;\n&#13;\n\/\/ LDAP password hash type&#13;\n\/\/ Standard LDAP encryption type which must be one of: crypt,&#13;\n\/\/ ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, or clear.&#13;\n\/\/ Please note that most encodage types require external libraries&#13;\n\/\/ to be included in your PHP installation, see function hashPassword in drivers\/ldap.php for more info.&#13;\n\/\/ Default: 'crypt'&#13;\n$rcmail_config['password_ldap_encodage'] = 'crypt';&#13;\n&#13;\n\/\/ LDAP password attribute&#13;\n\/\/ Name of the ldap's attribute used for storing user password&#13;\n\/\/ Default: 'userPassword'&#13;\n$rcmail_config['password_ldap_pwattr'] = 'userPassword';&#13;\n&#13;\n\/\/ LDAP password force replace&#13;\n\/\/ Force LDAP replace in cases where ACL allows only replace not read&#13;\n\/\/ See http:\/\/pear.php.net\/package\/Net_LDAP2\/docs\/latest\/Net_LDAP2\/Net_LDAP2_Entry.html#methodreplace&#13;\n\/\/ Default: true&#13;\n$rcmail_config['password_ldap_force_replace'] = true;<\/pre>\n<p>To:<\/p>\n<pre>$rcmail_config['password_ldap_host'] = 'localhost';&#13;\n$rcmail_config['password_ldap_port'] = '389';&#13;\n$rcmail_config['password_ldap_starttls'] = false;&#13;\n$rcmail_config['password_ldap_version'] = '3';&#13;\n$rcmail_config['password_ldap_basedn'] = 'o=hosting,dc=example,dc=tld';&#13;\n&#13;\n$rcmail_config['password_ldap_method'] = 'user';&#13;\n$rcmail_config['password_ldap_adminDN'] = null;&#13;\n$rcmail_config['password_ldap_adminPW'] = null;&#13;\n&#13;\n$rcmail_config['password_ldap_userDN_mask'] = 'mail=%login,vd=%domain,o=hosting,dc=example,dc=tld';&#13;\n&#13;\n$rcmail_config['password_ldap_encodage'] = 'md5';&#13;\n$rcmail_config['password_ldap_pwattr'] = 'userPassword';&#13;\n&#13;\n$rcmail_config['password_ldap_force_replace'] = true;<\/pre>\n<p>Now we&#8217;re going to download and install the vacation plugin:<\/p>\n<p class=\"command\">cd \/usr\/src<br \/>wget\u00a0https:\/\/github.com\/bhuisgen\/rc-vacation\/archive\/master.zip<br \/>unzip rc-vacation-master.zip<br \/>mv rc-vacation \/var\/www\/roundcube\/plugins\/vacation<br \/>cd \/var\/www\/roundcube\/plugins\/vacation<\/p>\n<p>Now we edit the configuration and change:<\/p>\n<p class=\"command\">nano plugins\/vacation\/config.inc.php<\/p>\n<p>Change:<\/p>\n<pre>$rcmail_config['vacation_gui_vacationsubject'] = TRUE;<\/pre>\n<p>To:<\/p>\n<pre>$rcmail_config['vacation_gui_vacationsubject'] = FALSE;<\/pre>\n<p>Change:<\/p>\n<pre>$rcmail_config['vacation_driver'] = 'sql'; <\/pre>\n<p>To:<\/p>\n<pre>$rcmail_config['vacation_driver'] = 'ldap';<\/pre>\n<p>Change:<\/p>\n<pre>\/\/ Base DN&#13;\n$rcmail_config['vacation_ldap_base'] = 'dc=ldap,dc=my,dc=domain';&#13;\n&#13;\n\/\/ Bind DN&#13;\n$rcmail_config['vacation_ldap_binddn'] =&#13; 'cn=user,dc=ldap,dc=my,dc=domain';&#13;\n&#13;\n\/\/ Bind password&#13;\n$rcmail_config['vacation_ldap_bindpw'] = 'pa$$w0rd';<\/pre>\n<p>To:<\/p>\n<pre>\/\/ Base DN&#13;\n$rcmail_config['vacation_ldap_base'] = 'o=hosting,dc=example,dc=tld';&#13;\n&#13;\n\/\/ Bind DN&#13;\n$rcmail_config['vacation_ldap_binddn'] = 'cn=admin,dc=example,dc=tld';&#13;\n&#13;\n\/\/ Bind password&#13;\n$rcmail_config['vacation_ldap_bindpw'] = 'yourpassword';<\/pre>\n<p>Change:<\/p>\n<pre>\/\/ Search filter to read data&#13;\n$rcmail_config['vacation_ldap_search_filter'] = '(objectClass=mailAccount)';&#13;\n&#13;\n\/\/ Search attributes to read data&#13;\n$rcmail_config['vacation_ldap_search_attrs'] = array ('vacationActive', 'vacationInfo');&#13;\n&#13;\n\/\/ array of DN to use for modify operations required to write data.&#13;\n$rcmail_config['vacation_ldap_modify_dns'] = array (&#13; 'cn=%email_local,ou=Mailboxes,dc=%email_domain,ou=MailServer,dc=ldap,dc=my,dc=domain'&#13;\n);<\/pre>\n<p>To:<\/p>\n<pre>\/\/ Search base to read data&#13;\n$rcmail_config['vacation_ldap_search_base'] =&#13; 'mail=%username,vd=%email_domain,o=hosting,dc=example,dc=tld';&#13;\n&#13;\n\/\/ Search filter to read data&#13;\n$rcmail_config['vacation_ldap_search_filter'] = '(objectClass=VirtualMailAccount)';&#13;\n&#13;\n\/\/ Search attributes to read data&#13;\n$rcmail_config['vacation_ldap_search_attrs'] = array ('vacationActive', 'vacationInfo');&#13;\n&#13;\n\/\/ array of DN to use for modify operations required to write data.&#13;\n$rcmail_config['vacation_ldap_modify_dns'] = array (&#13; 'mail=%username,vd=%email_domain,o=hosting,dc=example,dc=tld'&#13;\n);<\/pre>\n<p>We have to change the document root in the Apche2 server configuration so that Roundcube can be accessed.<\/p>\n<p class=\"command\">nano \/etc\/apache2\/sites-enabled\/000-default.conf<\/p>\n<p>And change from:<\/p>\n<pre><span>DocumentRoot \/var\/www\/html<br\/><\/span><\/pre>\n<p><span>To:<\/span><\/p>\n<pre><span>DocumentRoot \/var\/www\/<\/span><\/pre>\n<p>This concludes the configuration for Roundcube.<\/p>\n<h2 id=\"step-install-and-configure-proftpd\">Step 8: Install and configure proftpd<\/h2>\n<p>First, we will install proftpd and its requirements:<\/p>\n<p class=\"command\">apt install proftpd proftpd-mod-ldap<\/p>\n<p>Depending on your load you can decide between stand alone and inet.d.<\/p>\n<p>Note: You can copy the config files from examples\/proftpd to \/etc\/proftpd but for clarity, I will outline all of the configuration steps.<\/p>\n<p>Edit<span>\u00a0<\/span><span class=\"system\">\/etc\/proftpd\/proftpd.conf<\/span>:<\/p>\n<p class=\"command\">nano \/etc\/proftpd\/proftpd.conf<\/p>\n<p>And change from:<\/p>\n<pre># Use this to jail all users in their homes&#13;\n# DefaultRoot\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ~<\/pre>\n<p>To:<\/p>\n<pre># Use this to jail all users in their homes&#13;\nDefaultRoot\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/pre>\n<p>And change from:<\/p>\n<pre><span>#RequireValidShell \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0off<br\/><\/span><\/pre>\n<p><span>To:<\/span><\/p>\n<pre><span>RequireValidShell \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0off<\/span><\/pre>\n<p>And change:<\/p>\n<pre># Alternative authentication frameworks<br\/>#<br\/># Include \/etc\/proftpd\/ldap.conf<br\/>#Include \/etc\/proftpd\/sql.conf<\/pre>\n<p>To:<\/p>\n<pre># Alternative authentication frameworks<br\/>#<br\/>Include \/etc\/proftpd\/ldap.conf<br\/>#Include \/etc\/proftpd\/sql.conf<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ~<\/pre>\n<p>Now edit<span>\u00a0<\/span><span class=\"system\">\/etc\/proftpd\/modules.conf<\/span>:<\/p>\n<p class=\"command\">nano \/etc\/proftpd\/modules.conf<span>\u00a0<\/span><\/p>\n<p>And change from:<\/p>\n<pre># Install proftpd-mod-ldap to use this&#13;\n#LoadModule mod_ldap.c<\/pre>\n<p>To:<\/p>\n<pre># Install proftpd-mod-ldap to use this&#13;\nLoadModule mod_ldap.c<\/pre>\n<p>And from:<\/p>\n<pre># Install proftpd-mod-ldap to use this&#13;\n# LoadModule mod_quotatab_ldap.c<\/pre>\n<p>To:<\/p>\n<pre># Install proftpd-mod-ldap to use this&#13;\nLoadModule mod_quotatab_ldap.c <\/pre>\n<p>No edit<span>\u00a0<\/span><span class=\"system\">\/etc\/proftpd\/ldap.conf<\/span><span>\u00a0<\/span>and set the following:<\/p>\n<pre>&lt;IfModule mod_ldap.c&gt;<br\/>#<br\/>#LDAPServer ldap:\/\/ldap.example.com<br\/>#LDAPBindDN \"cn=admin,dc=example,dc=com\" \"admin_password\"<br\/>#LDAPUsers dc=users,dc=example,dc=com (uid=%u) (uidNumber=%u)<br\/>#LDAPUseTLS on<br\/>#<br\/>#<br\/>#LDAPServer ldaps:\/\/ldap.example.com<br\/>#LDAPBindDN \"cn=admin,dc=example,dc=com\" \"admin_password\"<br\/>#LDAPUsers dc=users,dc=example,dc=com (uid=%u) (uidNumber=%u)<br\/>#<br\/>LDAPServer ldap:\/\/127.0.0.1\/??sub<br\/>LDAPBindDN \"cn=vmail,o=hosting,dc=example,dc=tld \"readonly\"<br\/>LDAPUsers \"o=hosting,dc=example,dc=tld\" \"(&amp;(uid=%v)(objectclass=posixAccount))\"<br\/>LDAPDefaultGID 33<br\/>LDAPDefaultUID 33<br\/>LDAPForceDefaultGID True<br\/>LDAPForceDefaultUID True<p>&lt;\/IfModule&gt;<\/p><\/pre>\n<p>The following commands set the default user to www-data which suits me, you can change these values to suit your setup or leave them out to use the login uid \/ gid.<\/p>\n<pre>LDAPDefaultGID 33<br\/>LDAPDefaultUID 33<br\/>LDAPForceDefaultGID True<br\/>LDAPForceDefaultUID True<\/pre>\n<p>33 Is the uid\/gid of my testing setup, it can be different on your setup.<span>\u00a0<\/span><\/p>\n<p>This concludes the proftpd installation.<\/p>\n<h2 id=\"step-bringing-it-all-together\">Step 9: Bringing it all together<\/h2>\n<p>Issue the following commands to restart all of the services:<\/p>\n<p class=\"command\">service slapd restart<span>\u00a0<\/span><\/p>\n<p class=\"command\">service postfix restart<\/p>\n<p class=\"command\">service dovecot restart<\/p>\n<p class=\"command\">service proftpd\u00a0restart<\/p>\n<p class=\"command\">service apache2 restart<\/p>\n<p>Now you can go to phamm and start adding mail domains and users.<\/p>\n<p>Enjoy.<\/p>\n<p>Note: notify me of any errors or problems with this how to so I can improve and amend this how to.<span>\u00a0<\/span><\/p>\n<p><span>Use this thread in the forum:<\/span><\/p>\n<p><a href=\"https:\/\/www.howtoforge.com\/community\/threads\/postfix-virtual-hosting-with-ldap-backend-and-with-dovecot-as-imap-pop3-server-on-ubuntu-bionic-beav.79408\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.howtoforge.com\/community\/threads\/postfix-virtual-hosting-with-ldap-backend-and-with-dovecot-as-imap-pop3-server-on-ubuntu-bionic-beav.79408\/<\/a><\/p>\n<p>I am subscribed to this thread so I will get notifications of new posts in this thread.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Fpostfix-virtual-hosting-with-ldap-backend-and-dovecot-imap-pop3-server-on-ubuntu-bionic-beaver-1804-lts%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/postfix-virtual-hosting-with-ldap-backend-and-with-dovecot-as-imap-pop3-server-on-ubuntu-bionic-beaver-18-04-lts.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Fpostfix-virtual-hosting-with-ldap-backend-and-dovecot-imap-pop3-server-on-ubuntu-bionic-beaver-1804-lts%2F&amp;text=Postfix+Virtual+Hosting+With+LDAP+Backend+And+With+Dovecot+As+IMAP%2FPOP3+Server+On+Ubuntu+Bionic+Beaver+18.04+LTS&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/postfix-virtual-hosting-with-ldap-backend-and-with-dovecot-as-imap-pop3-server-on-ubuntu-bionic-beaver-18-04-lts-1.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/postfix-virtual-hosting-with-ldap-backend-and-with-dovecot-as-imap-pop3-server-on-ubuntu-bionic-beaver-18-04-lts-2.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Fpostfix-virtual-hosting-with-ldap-backend-and-dovecot-imap-pop3-server-on-ubuntu-bionic-beaver-1804-lts%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/postfix-virtual-hosting-with-ldap-backend-and-with-dovecot-as-imap-pop3-server-on-ubuntu-bionic-beaver-18-04-lts-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This howto will describe how to set up and configure virtual mail hosting with an\u00a0LDAP backend. The software\u00a0we will use in this howto:\u00a0Postfix\u00a0(MTA), Dovecot\u00a0(IMAP \/ POP3),\u00a0Gnarwl\u00a0(vacation), OpenLDAP\u00a0(LDAP)\u00a0 and\u00a0vMailpanel as the management interface. Optional are\u00a0Proftpd\u00a0FTP,\u00a0Roundcube\u00a0(webmail) and\u00a0MariaDB (SQL backend for Roundcube). This worked for me, but I cannot guarantee that this set up will work for you &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-5345","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=5345"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5345\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=5345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=5345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=5345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}