CentOS 快速搭建邮件服务
cyrus-sasl    账户认证(本地)
postfix       发送邮件
dovecot     接受邮件

一、系统配置

    所有账户邮件存放在 系统 /data/%U 目录下

    修改用户模板,新添加用户自动创建 Mail 目录用于存放邮件文件

    域:mxt.selboo.com.cn MX记录 mail.mxt.selboo.com.cn

用户模板下建立用户邮箱目录
[codes=txt][root@selboo ~]# mkdir /etc/skel/Mail
[root@selboo ~]# chmod 700 /etc/skel/Mail[/codes]
创建 "m1" 邮件账号
[codes=txt][root@selboo ~]# useradd -s /sbin/nologin -d /data/m1 m1[/codes]
修改 "m1" 密码 为 '12345567'
[codes=txt][root@selboo ~]# echo '12345567' | passwd --stdin m1
Changing password for user m1.
passwd: all authentication tokens updated successfully.[/codes]
安装软件
[codes=txt][root@selboo ~]# yum install postfix cyrus-sasl* dovecot[/codes]
二、cyrus-sasl 配置

1、修改 /etc/sysconfig/saslauthd 文件 使用本地认证

[codes=txt]cat /etc/sysconfig/saslauthd | grep -v '^#'
SOCKETDIR=/var/run/saslauthd
MECH=shadow[/codes]

2、修改 smtpd.conf
[codes=txt][root@selboo ~]#  cat /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login[/codes]

3、验证 sasl 是否正常
[codes=txt][root@selboo ~]# testsaslauthd -u m1 -p 12345567
0: OK "Success."[/codes]

三、Postfix配置

main.cf 配置文件
[codes=txt]cat /etc/postfix/main.cf | grep -v '^#'
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = mail.mxt.selboo.com.cn
mydomain = mxt.selboo.com.cn
myorigin = $myhostname
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
unknown_local_recipient_reject_code = 550
mynetworks_style = subnet
mynetworks  = 127.0.0.1
relay_domains = $mydestination
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

home_mailbox = Mail/
  
debug_peer_level = 2
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.6/samples
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

# sasl 认证
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,reject_unauth_destination,permit_mynetworks
smtpd_client_restrictions = permit_sasl_authenticated[/codes]
四、dovecot 配置

1、修改 /etc/dovecot/dovecot.conf 文件

[codes=txt][root@selboo ~]# cat /etc/dovecot/dovecot.conf | grep -E "protocols|listen ="
protocols = pop3
listen = *[/codes]只启用 POP3 和 只监听 IPV4 地址

2、关闭 POP3S 协议
[codes=txt][root@selboo ~]# cat /etc/dovecot/conf.d/10-ssl.conf | grep "ssl ="
ssl = no[/codes]
3、指定邮件目录
[codes=txt][root@selboo ~]# cat 10-mail.conf | grep "mail_location = maildir"
mail_location = maildir:~/Mail[/codes]
4、修改auto文件
[codes=txt][root@selboo ~]# cat 10-auth.conf | grep disable_plaintext_auth
disable_plaintext_auth = no[/codes]否在在收信时会出错 错误一

五、错误记录
1、错误一
/var/log/maillog 文件
dovecot: pop3-login: Disconnected (tried to use disabled plaintext auth)

2、错误二
/var/log/maillog 文件
Initialization failed: mail_location not set and autodetection failed: Mail storage autodetection fa

解决二
/etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Mail

参考文章:
http://book.selboo.com.cn/mail/postfix_smtp.html
http://book.selboo.com.cn/mail/dovecot_pop3.html
postfix 错误汇总
游客 | 登入