mysql> CREATE DATABASE postfixadmin; mysql> CREATE USER 'postfixadmin'@'localhost' IDENTIFIED BY 'YourPassword'; mysql> GRANT ALL PRIVILEGES ON `postfixadmin` . _config.landscape.yml _config.yml db.json Get_Joplin_resources.sh i18n Install_JavaScripts_via_npm.sh node_modules package.json package-lock.json public scaffolds source symlink.sh test.md themes tmp.md TO 'postfixadmin'@'localhost'; mysql> FLUSH PRIVILEGES;
Create a database for roundcubu.
1 2 3 4
mysql> CREATE DATABASE roundcube DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; mysql> CREATE USER roundcube@localhost IDENTIFIED BY 'YourPassword'; mysql> GRANT ALL PRIVILEGES ON roundcube.* TO roundcube@localhost; mysql> FLUSH PRIVILEGES;
Step3. Create Web Servers
Create Nginx config file for PostfixAdmin and RoundCube.
# A long browser cache lifetime can speed up repeat visits to your page # location ~* .(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ { # access_log off; # log_not_found off; # expires 360d; # }
#Add following to the end of the file. # Force TLSv1.3 or TLSv1.2 smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1 smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1 smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1 smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
mailbox_transport = lmtp:unix:private/dovecot-lmtp smtputf8_enable = no
Create new file and fill in the following. This will enable Dovecot to connect to our MySQL database.
1
# vim /etc/dovecot/dovecot-sql.conf.ext
1 2 3 4 5 6
driver = mysql connect = host=localhost dbname=postfixadmin user=postfixadmin password=YourPassword default_pass_scheme = SHA512 password_query = SELECT username AS user,password FROM mailbox WHERE username = '%u' AND active='1' user_query = SELECT maildir, 2000 AS uid, 2000 AS gid FROM mailbox WHERE username = '%u' AND active='1' iterate_query = SELECT username AS user FROM mailbox
Modify the file as below. This will define the mail location as well as the namespace.
1 2 3 4 5
# vim /etc/dovecot/conf.d/10-mail.conf # Add following in the end. mail_location = maildir:~/Maildir mail_home = /var/vmail/%d/%n mail_privileged_group = mail
Add the following lines to the end of this file.
1 2
# cp /etc/dovecot/conf.d/10-master.conf /etc/dovecot/conf.d/10-master.conf.bak # vim /etc/dovecot/conf.d/10-master.conf
1 2 3 4 5 6 7 8 9 10 11 12 13
#Add following in the end of the file. service stats { unix_listener stats-reader { user = nginx group = nginx mode = 0660 } unix_listener stats-writer { user = nginx group = nginx mode = 0660 } }
# vim /etc/dovecot/conf.d/10-master.conf # Change to: service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { mode = 0600 user = postfix group = postfix } } service auth { unix_listener /var/spool/postfix/private/auth { mode = 0600 user = postfix group = postfix } }
Edit the following file like below. This will auto-create Sent ,Junk, Draftsand Trash Folder.
# cp /etc/dovecot/conf.d/15-mailboxes.conf /etc/dovecot/conf.d/15-mailboxes.conf.bak # vim /etc/dovecot/conf.d/15-mailboxes.conf namespace inbox { # These mailboxes are widely used and could perhaps be created automatically: mailbox Drafts { auto = create special_use = Drafts } mailbox Junk { auto = create special_use = Junk } mailbox Trash { auto = create special_use = Trash } mailbox Sent { auto = create special_use = Sent } mailbox "Sent Messages" { special_use = Sent } }
Now we need to restart the Postfix and dovecot services.
1 2 3
# systemctl restart postfix dovecot # systemctl status postfix # systemctl status dovecot
Create following files and make sure they are set with permissions to be accessible by Postfix user.
1 2 3 4 5 6 7 8 9 10
# vim /etc/postfix/sql/mysql_virtual_domains_maps.cf user = postfixadmin password = YourPassword hosts = localhost dbname = postfixadmin query = SELECT domain FROM domain WHERE domain='%s' AND active = '1' #query = SELECT domain FROM domain WHERE domain='%s' #optional query to use when relaying for backup MX #query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1' #expansion_limit = 100
1 2 3 4 5 6 7
# vim /etc/postfix/sql/mysql_virtual_mailbox_maps.cf user = postfixadmin password = YourPassword hosts = localhost dbname = postfixadmin query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1' #expansion_limit = 100
1 2 3 4 5 6
# vim /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf user = postfixadmin password = YourPassword hosts = localhost dbname = postfixadmin query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
1 2 3 4 5 6 7
# vim /etc/postfix/sql/mysql_virtual_alias_maps.cf user = postfixadmin password = YourPassword hosts = localhost dbname = postfixadmin query = SELECT goto FROM alias WHERE address='%s' AND active = '1' #expansion_limit = 100
1 2 3 4 5 6
# vim /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf user = postfixadmin password = YourPassword hosts = localhost dbname = postfixadmin query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
1 2 3 4 5 6
# vim /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf user = postfixadmin password = YourPassword hosts = localhost dbname = postfixadmin query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
You can generate a password hash through php -r 'echo password_hash("YourPassword", PASSWORD_DEFAULT);' command. Now you need to add following line to the /usr/share/nginx/postfixadmin/config.local.php file in the end.
1
$CONF['setup_password'] = 'Your_Password's_Hash';
Follow the setup wizard to create an Administrator user and login.
Now you can create Domain and Mailboxes in PostfixAdmin.
Add your Private CA’s certificate in the end of the following file.
Note: This needs to be saved forcibly with :wq!.
1 2 3 4 5 6 7 8
# vim /etc/pki/tls/certs/ca-bundle.crt #Add the following to the end of the file. # My Private CA Certificate. -----BEGIN CERTIFICATE----- ... Your CA certificate. ... -----END CERTIFICATE-----
Next, you can scroll down to the Plugins section to enable some plugins. For example: the password plugin, mark as junk plugin and so on. I enabled all of them.
Make sure the password plugin in the plugin list at the end of this file. The plugin order doesn’t matter.
Create the new PHP file by copying the file below and modify it like following. This will enable RoundCube to connect our MySQL database and update password.
1 2
# cp /usr/share/nginx/roundcube/plugins/password/config.inc.php.dist /usr/share/nginx/roundcube/plugins/password/config.inc.php vim /usr/share/nginx/roundcube/plugins/password/config.inc.php
1 2 3 4 5 6 7 8 9
#Change the value to: $config['password_db_dsn'] = 'mysql://postfixadmin:[email protected]/postfixadmin'; $config['password_query'] = 'UPDATE mailbox SET password=%D,modified=NOW() WHERE username=%u'; $config['password_strength_driver'] = 'zxcvbn'; $config['password_zxcvbn_min_score'] = 5; $config['password_algorithm'] = 'dovecot'; $config['password_dovecotpw'] = '/usr/bin/doveadm pw -r 12'; $config['password_dovecotpw_method'] = 'SHA512'; $config['password_dovecotpw_with_method'] = true;
After completing the installation and the final tests please remove the whole installer folder from the document root of the webserver or make sure that enable_installer option in config.inc.php is disabled.
1 2 3 4
# rm -rf /usr/share/nginx/roundcube/installer/ vim /usr/share/nginx/roundcube/config/config.inc.php Change to: $config['enable_installer']=false;