1.安装Postfix
yum install postfix -y
2.安装Dovecot
yum -y install dovecot
3.配置Postfix
vim /etc/postfix/main.cf
修改如下:
#75行: 取消注释,设置hostname
myhostname = mailwestos.westos.com
#83行: 取消注释,设置域名
mydomain = westos.me
#99行: 取消注释
myorigin = $mydomain
#116行: 修改
inet_interfaces = all
#119行: 注释
inet_protocols = ipv4
#164行: 添加
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#添加到最后
#规定邮件最大尺寸为10M
message_size_limit = 10485760
#规定收件箱最大容量为1G
mailbox_size_limit = 1073741824
#SMTP认证
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
修改好了之后使用systemctl restart postfix 开启postfix,使用systemctl enable postfix 将postfix开机启动。
4.配置Dovecot
修改如下:
[root@mailwestos ~] #vim /etc/dovecot/dovecot.conf
#24行: 取消注释
protocols = imap pop3 lmtp
#48行: 更改
login_trusted_network = 0.0.0.0/0
#49行:添加
disable_plaintext_auth = no
[root@mailwestos ~] #vim /etc/dovecot/conf.d/10-mail.conf
#30行: 添加
mail_location = mbox:~/mail:INBOX=/var/mail/%u
[root@mailwestos ~] systemctl restart dovecot
Starting Dovecot Imap: [ OK ]
[root@mailwestos ~] #chkconfig dovecot on
到这里,我们的邮件服务器就已经搭建成功了。
但是配置/etc/dovecot/conf.d/10-mail.conf给的文件/mail:INBOX并不存在,需要手动创建:
mkdir /home/mail
touch /home/mail/INBOX
5.域名解析
最后别忘了还需要进行域名解析工作。
具体配置查看前面的DNS章节
添加一个子域名dns,A记录解析到服务器IP为172.25.254.100。
再添加一个MX记录,主机记录为空,记录值为上面解析的二级域名mailwestos.westos.com.,优先级1。
例如:
注意:解析生效可能需要一段时间。
6.邮箱使用
系统用户就是邮件的用户,例如student,就是一个邮箱用户,邮箱是student@westos.com,密码就是sthudent的密码
例如使用软件Thunderbird
这样就可以登陆如邮箱查看或者发送邮件