-安裝套件

# yum install postfix
# yum install dovecot
# yum install cyrus-sasl cyrus-sasl-md5

-編輯登入認證方式

# vi /etc/sysconfig/saslauthd
MECH=shadow


-編輯 Dovecot 設定

編輯文件 /etc/dovecot/conf.d/10-master.conf

# vi /etc/dovecot/conf.d/10-master.conf
unix_listener auth-userdb {
#mode = 0666
#user =
#group =
}

# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}


編輯文件 /etc/dovecot/conf.d/10-auth.conf

# vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login


編輯文件 /etc/dovecot/conf.d/10-ssl.conf

# vi /etc/dovecot/conf.d/10-ssl.conf
ssl=no


編輯文件 /etc/dovecot/dovecot.conf

# vi /etc/dovecot/dovecot.conf
protocols = pop3


編輯文件 /etc/dovecot/conf.d/10-mail.conf

# vi /etc/dovecot/conf.d/10-mail.conf
#mail_location = maildir:~/Maildir
mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u


-編輯 Postfix 設定

# vi /etc/postfix/main.cf

在最後面加入以下的內容

( Esc G = 移至該檔案的最後一列)

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination


-設定 SELinux

#setsebool -P postfix_local_write_mail_spool on

-設定防火牆

#firewall-cmd --permanent --add-service=smtp
#firewall-cmd --permanent --add-service=pop3
#firewall-cmd --reload

-啟動服務

# systemctl enable saslauthd.service
# systemctl restart saslauthd.service
# systemctl status saslauthd.service

# systemctl restart dovecot.service
# systemctl status dovecot.service

# systemctl restart postfix.service
# systemctl status postfix.service

-測試

# telnet localhost 25
ehlo localhost

如果有出現「AUTH=PLAIN LOGIN」,應該大致上沒有問題


PS:注意事項:

建立新增任一位使用者後 必須下達指令,解決 Operation Not Permitted 問題

# chmod 0600 /var/spool/mail/*

資料來源 https://wiki2.dovecot.org/Errors/ChgrpNoPerm



-Postfix 個人設定

編輯文件 /etc/postfix/main.cf

# vi /etc/postfix/main.cf
myhostname = mail.test.com.tw
mydomain = test.com.tw
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain