wget -q -O - \"http:\/\/downloads.sourceforge.net\/project\/postfixadmin\/postfixadmin\/postfixadmin-3.0\/postfixadmin-3.0.tar.gz\" | sudo tar -xzf - -C \/var\/www<\/pre>\nOpen the mail configuration file and edit the following values:<\/p>\n
sudo nano \/var\/www\/postfixadmin-3.0\/config.inc.php<\/pre>\n$CONF['configured'] = true;\r\n$CONF['database_type'] = 'sqlite';\r\n$CONF['database_name'] = '\/var\/vmail\/postfixadmin.db';\r\n\/\/ $CONF['database_host'] = 'localhost';\r\n\/\/ $CONF['database_user'] = 'postfix';\r\n\/\/ $CONF['database_password'] = 'postfixadmin';\r\n\/\/ $CONF['database_name'] = 'postfix';\r\n\r\n$CONF['domain_path'] = 'NO';\r\n$CONF['domain_in_mailbox'] = 'YES';\r\n<\/pre>\nsudo chown -R www-data: \/var\/www\/postfixadmin-3.0<\/pre>\nCreate the SQLite database:<\/p>\n
sudo touch \/var\/vmail\/postfixadmin.db\r\nsudo chown vmail:mail \/var\/vmail\/postfixadmin.db\r\nsudo usermod -a -G mail www-data<\/pre>\nTo populate the database go to https:\/\/postfixadmin.your_domain.com\/setup.php<\/code> and you should see something like below:
\nTesting database connection - OK - sqlite:\/\/:xxxxx@\/\/var\/vmail\/postfixadmin.db<\/code><\/p>\nCreate a new admin user:<\/p>\n
bash \/var\/www\/postfixadmin-3.0\/scripts\/postfixadmin-cli admin add admin@your_domain.com --password strong_password --password2 strong_password --superadmin 1 --active 1\r\n<\/pre>\n<\/span>7. Install and configure postfix<\/span><\/h2>\nInstall postfix with the command below:<\/p>\n
sudo apt-get install postfix<\/pre>\nCreate the following files:<\/p>\n
sudo nano \/etc\/postfix\/sqlite_virtual_alias_maps.cf<\/pre>\ndbpath = \/var\/vmail\/postfixadmin.db\r\nquery = SELECT goto FROM alias WHERE address='%s' AND active = '1'<\/pre>\n sudo nano \/etc\/postfix\/sqlite_virtual_alias_domain_maps.cf<\/pre>\ndbpath = \/var\/vmail\/postfixadmin.db\r\nquery = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = printf('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'<\/pre>\n sudo nano \/etc\/postfix\/sqlite_virtual_alias_domain_catchall_maps.cf<\/pre>\ndbpath = \/var\/vmail\/postfixadmin.db\r\nquery = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = printf('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'<\/pre>\n sudo nano \/etc\/postfix\/sqlite_virtual_domains_maps.cf<\/pre>\ndbpath = \/var\/vmail\/postfixadmin.db\r\nquery = SELECT domain FROM domain WHERE domain='%s' AND active = '1'<\/pre>\n sudo nano \/etc\/postfix\/sqlite_virtual_mailbox_maps.cf<\/pre>\ndbpath = \/var\/vmail\/postfixadmin.db\r\nquery = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'<\/pre>\n sudo nano \/etc\/postfix\/sqlite_virtual_alias_domain_mailbox_maps.cf<\/pre>\ndbpath = \/var\/vmail\/postfixadmin.db\r\nquery = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = printf('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'<\/pre>\nEdit the main.cf<\/code> file:<\/p>\npostconf -e \"myhostname = $(hostname -A)\"\r\n \r\npostconf -e \"virtual_mailbox_domains = sqlite:\/etc\/postfix\/sqlite_virtual_domains_maps.cf\"\r\npostconf -e \"virtual_alias_maps = sqlite:\/etc\/postfix\/sqlite_virtual_alias_maps.cf, sqlite:\/etc\/postfix\/sqlite_virtual_alias_domain_maps.cf, sqlite:\/etc\/postfix\/sqlite_virtual_alias_domain_catchall_maps.cf\"\r\npostconf -e \"virtual_mailbox_maps = sqlite:\/etc\/postfix\/sqlite_virtual_mailbox_maps.cf, sqlite:\/etc\/postfix\/sqlite_virtual_alias_domain_mailbox_maps.cf\"\r\n \r\npostconf -e \"smtpd_tls_cert_file = \/etc\/ssl\/certs\/ssl-cert-snakeoil.pem\"\r\npostconf -e \"smtpd_tls_key_file = \/etc\/ssl\/private\/ssl-cert-snakeoil.key\"\r\npostconf -e \"smtpd_use_tls = yes\"\r\npostconf -e \"smtpd_tls_auth_only = yes\"\r\n \r\npostconf -e \"smtpd_sasl_type = dovecot\"\r\npostconf -e \"smtpd_sasl_path = private\/auth\"\r\npostconf -e \"smtpd_sasl_auth_enable = yes\"\r\npostconf -e \"smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination\"\r\n \r\npostconf -e \"mydestination = localhost\"\r\npostconf -e \"mynetworks = 127.0.0.0\/8\"\r\npostconf -e \"inet_protocols = ipv4\"\r\n \r\npostconf -e \"virtual_transport = lmtp:unix:private\/dovecot-lmtp\"\r\n<\/pre>\nOpen the master.cf<\/code> file, find submission inet n<\/code> and smtps inet n<\/code> sections and edit as follows:<\/p>\nsudo nano \/etc\/postfix\/master.cf<\/pre>\nsmtp inet n - y - - smtpd\r\n#smtp inet n - y - 1 postscreen\r\n#smtpd pass - - y - - smtpd\r\n#dnsblog unix - - y - 0 dnsblog\r\n#tlsproxy unix - - y - 0 tlsproxy\r\nsubmission inet n - y - - smtpd\r\n -o syslog_name=postfix\/submission\r\n -o smtpd_tls_security_level=encrypt\r\n -o smtpd_sasl_auth_enable=yes\r\n# -o smtpd_reject_unlisted_recipient=no\r\n -o smtpd_client_restrictions=permit_sasl_authenticated,reject\r\n# -o smtpd_helo_restrictions=$mua_helo_restrictions\r\n# -o smtpd_sender_restrictions=$mua_sender_restrictions\r\n# -o smtpd_recipient_restrictions=\r\n# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject\r\n -o milter_macro_daemon_name=ORIGINATING\r\nsmtps inet n - y - - smtpd\r\n -o syslog_name=postfix\/smtps\r\n# -o smtpd_tls_wrappermode=yes\r\n -o smtpd_sasl_auth_enable=yes\r\n# -o smtpd_reject_unlisted_recipient=no\r\n -o smtpd_client_restrictions=permit_sasl_authenticated,reject\r\n# -o smtpd_helo_restrictions=$mua_helo_restrictions\r\n# -o smtpd_sender_restrictions=$mua_sender_restrictions\r\n# -o smtpd_recipient_restrictions=\r\n# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject\r\n -o milter_macro_daemon_name=ORIGINATING\r\n<\/pre>\nEnable and restart the postfix service<\/p>\n
systemctl enable postfix\r\nsystemctl restart postfix\r\n<\/pre>\n<\/span>8. Install and Configure Dovecot<\/span><\/h2>\nInstall dovecot with sqlite support using the command below:<\/p>\n
sudo apt-get install dovecot-imapd dovecot-lmtpd dovecot-pop3d dovecot-sqlite<\/pre>\nOpen the \/etc\/dovecot\/conf.d\/10-mail.conf<\/code> file and change the following values:<\/p>\nmail_location = maildir:\/var\/vmail\/%d\/%n\r\nmail_privileged_group = mail\r\nmail_uid = vmail\r\nmail_gid = mail\r\nfirst_valid_uid = 150\r\nlast_valid_uid = 150\r\n<\/pre>\nOpen the \/etc\/dovecot\/conf.d\/10-auth.conf<\/code> file and change the following values:<\/p>\nauth_mechanisms = plain login\r\n#!include auth-system.conf.ext\r\n!include auth-sql.conf.ext\r\n<\/pre>\nCreate a new dovecot-sql.conf.ext<\/code> file:<\/p>\nsudo nano \/etc\/dovecot\/dovecot-sql.conf.ext<\/pre>\ndriver = sqlite\r\nconnect = \/var\/vmail\/postfixadmin.db\r\ndefault_pass_scheme = MD5-CRYPT\r\npassword_query = \\\r\n SELECT username as user, password, '\/var\/vmail\/%d\/%n' as userdb_home, \\\r\n 'maildir:\/var\/vmail\/%d\/%n' as userdb_mail, 150 as userdb_uid, 8 as userdb_gid \\\r\n FROM mailbox WHERE username = '%u' AND active = '1'\r\nuser_query = \\\r\n SELECT '\/var\/vmail\/%d\/%n' as home, 'maildir:\/var\/vmail\/%d\/%n' as mail, \\\r\n 150 AS uid, 8 AS gid, printf('dirsize:storage=', quota) AS quota \\\r\n FROM mailbox WHERE username = '%u' AND active = '1'\r\n<\/pre>\nIn the \/etc\/dovecot\/conf.d\/10-ssl.conf<\/code> file enable SSL support:<\/p>\nssl = yes<\/pre>\n.<\/p>\n
Open the \/etc\/dovecot\/conf.d\/15-lda.conf<\/code> file and set the postmaster_address<\/code> email address.<\/p>\npostmaster_address = postmaster@vps.your_domain.com<\/pre>\nOpen the \/etc\/dovecot\/conf.d\/10-master.conf<\/code> file, find the service lmtp section and change it to:<\/p>\nservice lmtp {\r\n unix_listener \/var\/spool\/postfix\/private\/dovecot-lmtp {\r\n mode = 0600\r\n user = postfix\r\n group = postfix\r\n }\r\n}\r\n<\/pre>\nfind the service auth section and change it to:<\/p>\n
service auth {\r\n unix_listener \/var\/spool\/postfix\/private\/auth {\r\n mode = 0666\r\n user = postfix\r\n group = postfix\r\n }\r\n unix_listener auth-userdb {\r\n mode = 0600\r\n user = vmail\r\n #group = vmail\r\n }\r\n user = dovecot\r\n}\r\n<\/pre>\nChange the service auth-worker section to the following:<\/p>\n
service auth-worker {\r\n user = vmail\r\n}<\/pre>\nSet the permissions:<\/p>\n
chown -R vmail:dovecot \/etc\/dovecot\r\nchmod -R o-rwx \/etc\/dovecot<\/pre>\nEnable and restart the dovecot service<\/p>\n
systemctl enable dovecot \r\nsystemctl restart dovecot \r\n<\/pre>\n