DNS解析
要通过mxawei.cn一级域名收发邮件,A记录是必须的。如果只是通过二级域名(如mail.mxawei.cn)收发,只要有条CNAME就行了。
没有固定IP太蛋痛了!!!-_-#
安装Postfix
- 安装程序
yum install 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 = mxawei.cn
mydomain = mxawei.cn
myorigin = mxawei.cn
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
mynetworks = 192.168.1.0/28, 127.0.0.0/8
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
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: The location of the Postfix HTML documentation.
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
mailbox_size_limit = 102400000
message_size_limit = 102400000
#awei add
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/pki/tls/private/3_mxawei.cn.key
smtpd_tls_cert_file = /etc/pki/tls/certs/2_mxawei.cn.crt
smtpd_tls_CAfile = /etc/pki/tls/certs/1_root_bundle.crt
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
- 编辑master.cf
smtp inet n - n - - smtpd
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
pickup unix n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr unix n - n 300 1 qmgr
tlsmgr unix - - n 1000? 1 tlsmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
defer unix - - n - 0 bounce
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - n - - smtp
relay unix - - n - - smtp
showq unix n - n - - showq
error unix - - n - - error
retry unix - - n - - error
discard unix - - n - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache
- 启动服务
systemctl restart postfix
systemctl enable postfix
- 防火墙
firewall-cmd --zone=public --permanent --add-port=465/tcp #支持smtps功能
firewall-cmd --zone=public --permanent --add-service=smtp #防火墙要开放25端口,要不收不到外面的邮件;只支持SMTPS,可以不开这个服务端口。
firewall-cmd --zone=public --permanent --add-port=993/tcp #防火墙要开放993端口,要不外面的客户端无法收件
安装Dovecot
- 安装
yum install dovecot
- 编辑dovecot.conf
文件内容如下
# 2.2.10: /etc/dovecot/dovecot.conf
# OS: Linux 3.10.0-229.7.2.el7.x86_64 x86_64 CentOS Linux release 7.1.1503 (Core)
mail_location = mbox:~/mail:INBOX=/var/mail/%u
mbox_write_locks = fcntl
namespace inbox {
inbox = yes
location =
mailbox Drafts {
special_use = \Drafts
}
mailbox Junk {
special_use = \Junk
}
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
mailbox Trash {
special_use = \Trash
}
prefix =
}
passdb {
driver = pam
}
protocols = imap pop3
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0660
user = postfix
}
}
ssl = required
ssl_cert = </etc/ssl/certs/2_mxawei.cn.crt
ssl_key = </etc/pki/tls/private/3_mxawei.cn.key
userdb {
driver = passwd
}
- 启动程序
systemctl enable dovecot
systemctl restart dovecot
测试邮件服务器
yum install mailx
mail -s test awei@mxawei.cn
安装SquireelMail
- 安装
建议安装SNV版,中文支持方面好像好些。
yum install subversion
svn checkout https://svn.code.sf.net/p/squirrelmail/code/branches/SM-1_4-STABLE/squirrelmail
ln -s squirrelmail webmail #webmail为Webmail的虚拟主机目录
- SquirelMail设置,看图罢
- Selinux设置
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_sendmail 1
getsebool httpd_can_network_connect # 查看开启情况
chcon -R -t httpd_sys_script_rw_t data #允许data目录可写
- 权限设置
chmod 0600 /var/mail/*
要不,无法读取邮件。
Related content
- 在Centos7上通过certbot自动为Apache部署Let’s Encrypt SSL证书
- Centos7.2使Apache支持Https协议
- CentOS7下用Postfixadmin+Postfix+Dovecot搭建支持虚拟用户的邮件系统