==============设置hostname====================

hostname mail.vip.demo.com

==============安装telnet======================

yum -y install telnet

==============安装postfix/cyrus-sasl/dovecot======================

======================安装 postfix======================
yum -y install postfix*
rpm -ql postfix|more
yum -y install openssl

chkconfig --level 2345 postfix on

/etc/init.d/postfix restart

======================安装 cyrus-sasl======================

rpm -qa | grep sasl

yum install cyrus-sasl*

# 检查 saslauthd 中的三项
=========================
vim /etc/sysconfig/saslauthd

SOCKETDIR=/run/saslauthd
MECH=shadow
FLAGS=

=========================

ps aux | grep saslauthd
chkconfig --level 2345 saslauthd on
systemctl start saslauthd
ps aux | grep saslauthd
reboot
ps aux | grep saslauthd

systemctl restart saslauthd

======================安装dovecot======================

yum -y install dovecot

systemctl restart dovecot


chkconfig --level 2345 dovecot on

==============配置postfix/dovecot======================
   
1、 配置postfix--- main.cf

find / -name 'main.cf'

cd /etc/postfix/

cp -p main.cf main.cf.bak

cp -p master.cf master.cf.bak

# vim /etc/postfix/main.cf

// 以下为模板
==================================================
queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/libexec/postfix

data_directory = /var/lib/postfix

mail_owner = postfix

myhostname = mail.vip.demo.com

mydomain = vip.demo.com

myorigin = $mydomain

inet_interfaces = all

inet_protocols = ipv4

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

local_recipient_maps = unix:passwd.byname $alias_maps

unknown_local_recipient_reject_code = 550

mynetworks_style = class

mynetworks = 0.0.0.0/0

relay_domains = $mydestination

#relayhost = $mydomain
#relayhost = [gateway.my.domain]
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]

relay_recipient_maps = hash:/etc/postfix/relay_recipients

in_flow_delay = 1s

alias_maps = hash:/etc/aliases

alias_database = dbm:/etc/aliases

#recipient_delimiter = +

#home_mailbox = Mailbox
#home_mailbox = Maildir/
 
#mail_spool_directory = /var/mail
#mail_spool_directory = /var/spool/mail

#mailbox_command = /some/where/procmail
#mailbox_command = /some/where/procmail -a "$EXTENSION"

#mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp

#mailbox_transport = cyrus

#fallback_transport = lmtp:unix:/var/lib/imap/socket/lmtp
#fallback_transport =

#luser_relay = $user@other.host
#luser_relay = $local@other.host
#luser_relay = admin+$local

#header_checks = regexp:/etc/postfix/header_checks

fast_flush_domains = $relay_domains

smtpd_banner = $myhostname ESMTP

# 规定邮件最大尺寸为10M
message_size_limit = 10485760
# 规定收件箱最大容量为1G
mailbox_size_limit = 1073741824

local_destination_concurrency_limit = 2

debug_peer_level = 2

debugger_command =
	 PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
	 ddd $daemon_directory/$process_name $process_id & sleep 5

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.10.1/samples

readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES

################################

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous

broken_sasl_auth_clients = yes 
smtpd_sasl_authenticated_header = yes 

smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject

smtpd_tls_auth_only = yes 
smtp_use_tls = yes 
smtpd_use_tls = yes 
smtp_tls_note_starttls_offer = yes

smtpd_tls_security_level = may
smtpd_tls_key_file = /etc/pki/tls/certs/mail.vip.demo.com.key 
smtpd_tls_cert_file = /etc/pki/tls/certs/mail.vip.demo.com.pem 
smtpd_tls_loglevel = 0

========================================================

2、 配置postfix--- master.cf

# vim /etc/postfix/master.cf  ## [SSL]

smtps       inet   n       -       n       -       -       smtpd
  -o smtpd_tls_wrappermode=yes

配置后，重启
/etc/init.d/postfix start

========================================================

cp -p /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.bak
cp -p /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf.bak
cp -p /etc/dovecot/conf.d/10-mail.conf /etc/dovecot/conf.d/10-mail.conf.bak
cp -p /etc/dovecot/conf.d/10-master.conf /etc/dovecot/conf.d/10-master.conf.bak
cp -p /etc/dovecot/conf.d/10-ssl.conf /etc/dovecot/conf.d/10-ssl.conf.bak

3、 配置Dovecot--- dovecot.conf

vi /etc/dovecot/dovecot.conf

#如果不使用IPv6，请修改为
listen = * 

4、 配置Dovecot--- 10-auth.conf

vi /etc/dovecot/conf.d/10-auth.conf

# 明文授权
disable_plaintext_auth = no

auth_mechanisms = plain login

5、 配置Dovecot--- 10-mail.conf

vi /etc/dovecot/conf.d/10-mail.conf

mail_location = mbox:~/mail:INBOX=/var/mail/%u

6、 配置Dovecot--- 10-master.conf

vi /etc/dovecot/conf.d/10-master.conf

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

7、 配置Dovecot--- 10-ssl.conf
# 配置支持SSL

vi /etc/dovecot/conf.d/10-ssl.conf

ssl = yes
# 指定证书
ssl_cert = </etc/pki/tls/certs/mail.vip.demo.com.pem
ssl_key = </etc/pki/tls/certs/mail.vip.demo.com.key

# 然后启动服务
/etc/init.d/postfix restart
systemctl restart dovecot

==============其他相关命令======================

查看系统用户数量
vim /etc/passwd

# 创建用户
useradd nineven
#设置密码，会要求输入两次密码
passwd nineven

-ERR [SYS/PERM] Permission denied

cd /etc/postfix

useradd c1688; echo 123456q | passwd -- stdin c1688;
mkdir -p /home/c1688/mail/.imap/INBOX/
chown -R c1688.c1688 /home/c1688/
配置相关文件

reboot

netstat -ntl  // 核对 465 993，25端口是否启用

chmod 0600 /var/spool/mail/*
查看用户
vim  /etc/passwd
passwd c1688

==============域名相关配置======================

主域名：demo.com
检验地址
https://www.kitterman.com/spf/validate.html

-------------一级域名发送邮件-------------------

pop3:	mail.demo.com
smtp:	mail.demo.com
email:	test@demo.com

添加A、MX、TXT记录

记录值	记录类型		记录值
mail 	A 			mailServerIP
@		MX 			mail.demo.com
@		TXT 		v=spf1 ip4:mailServerIP a mx -all
_dmarc	TXT			v=DMARC1;p=quarantine;rua=mailto:admin@demo.com	

-------------二级域名发送邮件-------------------

pop3:	mail.vip.demo.com
smtp:	mail.vip.demo.com
email:	test@vip.demo.com

添加A、MX、TXT记录

记录值		记录类型		记录值
mail.vip 	A 			mailServerIP
vip			MX 			mail.vip.demo.com
vip			TXT 		v=spf1 ip4:mailServerIP a mx -all
_dmarc		TXT			v=DMARC1;p=quarantine;rua=mailto:admin@vip.demo.com	