CentOS搭建邮件服务
cyrus-sasl 账户认证(本地)
postfix 发送邮件
dovecot 接受邮件
一、系统配置
所有账户邮件存放在 系统 /data/%U 目录下
修改用户模板,新添加用户自动创建 Mail 目录用于存放邮件文件
域:mxt.selboo.com.cn MX记录 mail.mxt.selboo.com.cn
用户模板下建立用户邮箱目录
This is The Code
[root@selboo ~]# mkdir /etc/skel/Mail
[root@selboo ~]# chmod 700 /etc/skel/Mail
Parsed in 0.000 seconds at N/A
创建 "m1" 邮件账号
This is The Code
[root@selboo ~]# useradd -s /sbin/nologin -d /data/m1 m1
Parsed in 0.000 seconds at N/A
修改 "m1" 密码 为 '12345567'
This is The Code
[root@selboo ~]# echo '12345567' | passwd --stdin m1
Changing password for user m1.
passwd: all authentication tokens updated successfully.
Parsed in 0.000 seconds at N/A
安装软件
This is The Code
[root@selboo ~]# yum install postfix cyrus-sasl* dovecot
Parsed in 0.000 seconds at N/A
二、cyrus-sasl 配置
1、修改 /etc/sysconfig/saslauthd 文件 使用本地认证
This is The Code
cat /etc/sysconfig/saslauthd | grep -v '^#'
SOCKETDIR=/var/run/saslauthd
MECH=shadow
Parsed in 0.000 seconds at N/A
2、修改 smtpd.conf
This is The Code
[root@selboo ~]# cat /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
Parsed in 0.000 seconds at N/A
3、验证 sasl 是否正常
This is The Code
[root@selboo ~]# testsaslauthd -u m1 -p 12345567
0: OK "Success."
Parsed in 0.000 seconds at N/A
三、Postfix配置
main.cf 配置文件
This is The Code
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
Parsed in 0.000 seconds at N/A
四、dovecot 配置
1、修改 /etc/dovecot/dovecot.conf 文件
This is The Code
[root@selboo ~]# cat /etc/dovecot/dovecot.conf | grep -E "protocols|listen ="
protocols = pop3
listen = *
Parsed in 0.000 seconds at N/A
只启用 POP3 和 只监听 IPV4 地址
2、关闭 POP3S 协议
This is The Code
[root@selboo ~]# cat /etc/dovecot/conf.d/10-ssl.conf | grep "ssl ="
ssl = no
Parsed in 0.000 seconds at N/A
3、指定邮件目录
This is The Code
[root@selboo ~]# cat 10-mail.conf | grep "mail_location = maildir"
mail_location = maildir:~/Mail
Parsed in 0.000 seconds at N/A
4、修改auto文件
This is The Code
[root@selboo ~]# cat 10-auth.conf | grep disable_plaintext_auth
disable_plaintext_auth = no
Parsed in 0.000 seconds at N/A
否在在收信时会出错 错误一
五、错误记录
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
CentOS搭建邮件服务-虚拟域
这次给 Postfix 添加虚拟域
域 地址 MX记录 系统目录(%U 用户主目录)
mxt.selboo.com.cn m1@mxt.selboo.com.cn mail.mxt.selboo.com.cn /data/%U
mxy.selboo.com.cn m2@mxy.selboo.com.cn mail.mxy.selboo.com.cn /mxy/%U
一、添加用户
This is The Bash Code
useradd -d /data/m1 m1 -s /sbin/nologin
useradd -d /mxy/m2 m2 -s /sbin/nologin
修改密码
echo '12345567' | passwd --stdin m1
echo '12345567' | passwd --stdin m2
获取id
id m1
uid=513(m1) gid=513(m1) groups=513(m1)
id m2
uid=514(m2) gid=514(m2) groups=514(m2)
Parsed in 0.019 seconds at 13.30 KB/s
二、配置 Postfix
修改 main.cf 添加以下参数
This is The Code
virtual_alias_maps = hash:/etc/postfix/virtual_alias_maps
virtual_mailbox_domains = /etc/postfix/virtual_mailbox_domains
virtual_mailbox_maps = hash:/etc/postfix/virtual_mailbox_maps
virtual_uid_maps = hash:/etc/postfix/virtual_uids
virtual_gid_maps = hash:/etc/postfix/virtual_gids
virtual_mailbox_base = /
virtual_maildir_extended = yes
virtual_create_maildirsize = yes
Parsed in 0.000 seconds at N/A
virtual_alias_maps 转发配置
virtual_mailbox_domains 域配置
virtual_mailbox_maps 用户目录配置
virtual_uid_maps UID
virtual_gid_maps GID
This is The Code
cat /etc/postfix/virtual_alias_maps
m1@mxt.selboo.com.cn m1@mxt.selboo.com.cn,m2@mxy.selboo.com.cn
cat /etc/postfix/virtual_mailbox_domains
mxt.selboo.com.cn
mxy.selboo.com.cn
cat /etc/postfix/virtual_mailbox_maps
m1@mxt.selboo.com.cn /data/m1/Mail/
m2@mxy.selboo.com.cn /mxy/m2/Mail/
cat virtual_uids
m1@mxt.selboo.com.cn 513
m1@mxt.selboo.com.cn 514
cat virtual_gids
m1@mxt.selboo.com.cn 513
m1@mxt.selboo.com.cn 514
postmap /etc/postfix/virtual_alias_maps
postmap /etc/postfix/virtual_mailbox_maps
postmap /etc/postfix/virtual_uids
postmap /etc/postfix/virtual_gids
Parsed in 0.000 seconds at N/A
排错记录
一、/var/log/maillog 文件
fatal: bad string length 0 < 1: virtual_mailbox_base =
添加 virtual_mailbox_base = / 参数
二、/var/log/maillog 文件
warning: do not list domain mxt.selboo.com.cn in BOTH mydestination and virtual_mailbox_domains
mydomain 参数 和 virtual_mailbox_domains 有重复
PS:因为依赖本地系统用户,所以两个域不能有相同账户