vi \/etc\/postfix\/master.cf<\/pre>\nAdd or change the contents so that the file looks like this:<\/p>\n
smtp 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=$mua_client_restrictions\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 smtpd_client_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_client_restrictions=$mua_client_restrictions\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<\/pre>\nEnable the Postfix service to start on server boot and restart the Postfix service:<\/p>\n
systemctl enable postfix\r\nsystemctl restart postfix<\/pre>\nPostfix is finally installed and configured.<\/p>\n
<\/span>Step 6. Install Dovecot<\/span><\/h2>\nDovecot is a Mail Delivery Agent which allows a user to receive emails in complete security through IMAP and\/or POP3 protocols. We can install Dovecot and the dovecot-mysql<\/code> package using the command below:<\/p>\napt-get install dovecot-core dovecot-lmtpd dovecot-imapd dovecot-pop3d dovecot-mysql<\/pre>\nEdit the \/etc\/dovecot\/conf.d\/10-mail.conf<\/code> file:<\/p>\nvi \/etc\/dovecot\/conf.d\/10-mail.conf<\/pre>\nInsert this as the content:<\/p>\n
mail_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:<\/p>\nvi \/etc\/dovecot\/conf.d\/10-auth.conf<\/pre>\nEdit it so that the file looks like this:<\/p>\n
auth_mechanisms = plain login\r\n#!include auth-system.conf.ext\r\n!include auth-sql.conf.ext\r\n<\/pre>\nThen edit the\u00a0dovecot-sql.conf.ext<\/code> file, and add these lines:<\/p>\nvi \/etc\/dovecot\/dovecot-sql.conf.ext<\/pre>\ndriver = mysql\r\nconnect = host=localhost dbname=postfixadmin user=postfixadmin password=Strong_Password<\/span>\r\ndefault_pass_scheme = MD5-CRYPT\r\npassword_query = SELECT username as user, password, '\/var\/vmail\/%d\/%n' as userdb_home, 'maildir:\/var\/vmail\/%d\/%n' as userdb_mail, 150 as userdb_uid, 8 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'\r\nuser_query = SELECT '\/var\/vmail\/%d\/%u' as home, 'maildir:\/var\/vmail\/%d\/%u' as mail, 150 AS uid, 8 AS gid, concat('dirsize:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'<\/pre>\nDo not forget to replace Strong_Password<\/span> with the actual password that you set previously in Step 4 when creating the MariaDB user.<\/p>\nEdit the \/etc\/dovecot\/conf.d\/10-ssl.conf<\/code> file, and enable SSL support:<\/p>\nvi \/etc\/dovecot\/conf.d\/10-ssl.conf<\/pre>\nssl = yes<\/pre>\nSave and close that file, then edit the \/etc\/dovecot\/conf.d\/15-lda.conf<\/code> file and set the postmaster_address<\/code>\u00a0email address.<\/p>\nvi \/etc\/dovecot\/conf.d\/15-lda.conf<\/pre>\npostmaster_address = postmaster@yourdomain.com<\/span><\/pre>\nMake sure that you change yourdomain.com<\/span> to the actual domain name that points to your server.<\/p>\nEdit the \/etc\/dovecot\/conf.d\/10-master.conf<\/code> file, find the service lmtp<\/code> section and replace it with the following lines:<\/p>\nvi \/etc\/dovecot\/conf.d\/10-master.conf<\/pre>\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>\nOnce that part is edited, find the service auth<\/code> section and replace it with the following snippet:<\/p>\nservice 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\r\nunix_listener auth-userdb {\r\n mode = 0600\r\n user = vmail\r\n\r\n}\r\nuser = dovecot\r\n}\r\n\r\n<\/pre>\nThen change the service auth-worker<\/code> section to the following:<\/p>\nservice auth-worker {\r\nuser = vmail\r\n}<\/pre>\nSave and close the file.<\/p>\n
Set the correct permissions of the Dovecot configuration files:<\/p>\n
chown -R vmail:dovecot \/etc\/dovecot \r\nchmod -R o-rwx \/etc\/dovecot<\/pre>\nEnable the Dovecot service to start on server boot, and restart Dovecot so that all of these new configuration files are in effect:<\/p>\n
systemctl enable dovecot\r\nsystemctl restart dovecot<\/pre>\n