Postfix

   是一个标准的MTA[Mail Transfer Agent]服务器,塔负责通过SMTP协议管理发送到本机的邮件以及由本机发向外界的邮件

Dovecot

   是一个优秀的IMAP/POP服务器用以接受外界发送到本机的邮件

安装Postfix、Dovecot

# yum -y install postfix dovecot

配置Postfix(参照官方文档http://www.postfix.org/documentation.html

在终端输入以下命令,yourdomain.com改为自己的域名

postconf -e 'myhostname = server.yourdomain.com'
postconf -e 'mydestination = localhost, localhost.localdomain'
postconf -e 'myorigin = $mydomain'
postconf -e 'mynetworks = 127.0.0.0/8'
postconf -e 'inet_interfaces = all'
postconf -e 'inet_protocols = all'
postconf -e 'mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain'
postconf -e 'home_mailbox = Maildir/'
postconf -e 'smtpd_sasl_type = dovecot'
postconf -e 'smtpd_sasl_path = private/auth'
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem'
postconf -e 'smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem'

配置中Postfix使用sasl和tls来完成身份认证和传输信息加密。

试验中使用了Dovecot默认的ssl证书和私钥,可以按照自己的需要修改为自己的,替换最后两行的路径就好

配置smtps

# vi /etc/postfix/master.cf

将下面两行前的#去除
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes   =>此行要保留前面的空格

启动服务

# systemctl start postfix.service

Postfix日志

Postfix系统的日志文件在系统/var/log/maillog文件下

配置Dovecot

# vi /etc/dovecot/dovecot.conf
在配置文件最下方加入以下配置
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem

protocols = imap pop3 lmtp
listen = *
mail_location = Maildir:~/Maildir
disable_plaintext_auth = no

# vi /etc/dovecot/conf.d/10-master.conf
找到service auth部分,去除下行中开头的#
unix_listener /var/spool/postfix/private/auth {  
       mode = 0666  
}

启动Dovecot

# systemctl start dovecot.service

发送邮件

创建用户,利用新用户发送邮件

# useradd test
# passwd test
# su - test
$ echo "Mail Content" | mail -s "Mail Subject" xxxx@xxx.com

邮件客户端

可以将该邮箱账户添加进邮件客户端使用,推荐使用Foxmail客户端

可参考以下配置进行设置

服务器类型:`POP3`
邮箱账户:  `test@yourdomain.com`

收件(POP3)服务器:  `yourdomain.com`
端口:              `995`
安全连接(SSL):     `是`
用户名:            `test`
密码:              `test用户密码`

发件(SMTP)服务器:  `yourdomain.com`
端口:              `465`
安全连接(SSL):     `是`
用户名:            `test`
密码:              `test用户密码`