1. Goal
Build the postfix version of the mail server in centos7. (No pit version)
Second, the platform
centos7.6,postfix-2.10.1-7.el7.x86_64
Three, analysis
1.
2.
Four, Postfix mail server settings
1. Basic configuration
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
2. Modify the host name
hostnamectl set-hostname mail.hiibm.com
3. Modify the default mail transfer agent to MTA (after executing the following command, follow a carriage return to continue)
alternatives --config mta
4. Verify the MTA status (if the value is found, it basically means that there is no problem)
alternatives --display mta |grep "status is manual" && echo -e "\e[1;32mOK\e[0m" || echo -e "\e[1;31mNotOK\e[0m"
5. Install postfix
rpm -qa |grep postfix || yum install -y postfix
6. Modify the postfix main configuration file (a large part, just remove the comment line at the beginning of the # sign, copy and paste everything to execute, but you have to modify your network segment and domain name and other related information before executing)
cp /etc/postfix/main.cf{,.bak}
#1.设定邮箱域名
sed -i 's/#myhostname = host.domain.tld/myhostname = mail.hiibm.com/' /etc/postfix/main.cf
#2.设定邮箱的域
sed -i 's/#mydomain = domain.tld/mydomain = hiibm.com/' /etc/postfix/main.cf
#3.设定邮箱的域
sed -i 's/#myorigin = $mydomain/myorigin = $mydomain/' /etc/postfix/main.cf
#4.设定邮箱支持网络协议为ipv4(本步可略,略过的话就支持ipv4和ipv6)
sed -i 's/inet_protocols = all/inet_protocols = ipv4/' /etc/postfix/main.cf
#5.设定网络接口
sed -i 's/inet_interfaces = localhost/inet_interfaces = all/' /etc/postfix/main.cf
#6.设定域名
sed -i 's/mydestination = $myhostname, localhost.$mydomain, localhost/mydestination = $myhostname, localhost.$mydomain, localhost, \$mydomain/' /etc/postfix/main.cf
#7.设定postfix支持的网段
sed -i "s@#mynetworks = 168.100.189.0/28, 127.0.0.0/8@mynetworks = 192.168.0.0/24, 127.0.0.0/8@" /etc/postfix/main.cf
#设定邮箱用户收到的邮件存放的目录(即各邮箱用户的家目录下的Maildir目录下存手来的邮件)
sed -i "s@#home_mailbox = Maildir/@home_mailbox = Maildir/@" /etc/postfix/main.cf
#在第571行处增加banner
sed -i '571c smtpd_banner = \$myhostname ESMTP' /etc/postfix/main.cf
#指定收邮件用dovecot,并设置禁用匿名登录
cat >> /etc/postfix/main.cf <<EOF
message_size_limit = 10485760
mailbox_size_limit = 1073741824
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = \$myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject
EOF
7. Restart the postfix service
systemctl restart postfix
systemctl enable postfix
8. Install dovecot
rpm -qa |grep dovecot || yum install -y dovecot
9. Modify several configuration files of dovecot
cp /etc/dovecot/dovecot.conf{,.bak}
cp /etc/dovecot/conf.d/10-auth.conf{,.bak}
cp /etc/dovecot/conf.d/10-mail.conf{,.bak}
cp /etc/dovecot/conf.d/10-master.conf{,.bak}
cp /etc/dovecot/conf.d/10-ssl.conf{,.bak}
#1.修改dovecot仅支持ipv4协议
sed -i 's/#listen = \*, ::/listen = \*/' /etc/dovecot/dovecot.conf
#2.
sed -i 's/#disable_plaintext_auth = yes/disable_plaintext_auth = no/' /etc/dovecot/conf.d/10-auth.conf
$3.
sed -i 's/auth_mechanisms = plain/auth_mechanisms = plain login/' /etc/dovecot/conf.d/10-auth.conf
#4.
sed -i "s@#mail_location =@mail_location = maildir:~/Maildir@" /etc/dovecot/conf.d/10-mail.conf
10. Modify lines 96-98 of /etc/dovecot/conf.d/10-master.conf
Modify
#unix_listener /var/spool/postfix/private/auth { # mode = 0666 #} Modify to
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
11. Note: If we are not using ssl, we need to perform the following operations. No need if used.
sed -i 's/ssl = required/ssl = no/' /etc/dovecot/conf.d/10-ssl.conf
12. Start dovecot
systemctl restart dovecot
systemctl enable dovecot
Five, add mailbox users to Postfix
groupadd xmailusers
useradd -g xmailusers -s /sbin/nologin xmail1
useradd -g xmailusers -s /sbin/nologin xmail2
echo "A@#$123456" |passwd --stdin xmail1
echo "A@#$123456" |passwd --stdin xmail2
Six, use telnet to verify mail sending and receiving
1. Install the telnet tool
rpm -qa |grep telnet ||yum install -y telnet
2. Send mail using telnet verification under centos
telnet 127.0.0.1 25
helo mail.hiibm.com
mail from:[email protected]
rcpt to:[email protected]
data
i am xmail1,nihaoa
.
quit
3. View postfix mail in centos command line mode
#xmail2是之前创建的几个centos账号之一,一个邮件就是一个文件
cat /home/xmail2/Maildir/new/随机数字.随机字符.mail.hiibm.com
Seven, use Outlook to test mail sending and receiving
1.
2.
3.
4.
5.
The test is no problem. Old iron double-click 666
----------------------END---------2020/4/7 13:53:00------- ----------------
Reference document 1: https://www.cnblogs.com/operationhome/p/9056870.html
Reference document 2: https://blog.51cto.com/12227558/2074095