centos7 搭建 postfix

版权声明:hanxinkong提供技术支持 https://blog.csdn.net/hanxinkong/article/details/85803745

此配置只能在局域网中使用(属于同一个域,能接收外网邮件,不能发送邮件到外网)

本地 用户名@*********.***
远程 pop3 hxkemail.*********.***
远程 smtp hxkemail.*********.***
阿里云主机 开启端口 11025143, 995,465 (ssl)

DNS记录
mx
在这里插入图片描述
A
在这里插入图片描述

卸载sendmail
rpm -e sendmail 或者 yum remove sendmail

修改hostname
hostnamectl set-hostname hxkemail.******.***

修改MTA(默认邮件传输代理)
alternatives --config mta 【回车】
在这里插入图片描述
alternatives --display mta
mat - status is manual.就是ok
在这里插入图片描述

配置postfix
vim /etc/postfix/main.cf

# 75行: 取消注释,设置hostname 
myhostname = mail.abc.com 
# 83行: 取消注释,设置域名 
mydomain = abc.com 
# 99行: 取消注释 
myorigin = $mydomain 
# 116行: 默认是localhost,我们需要修改成all
inet_interfaces = all 
# 119行: 推荐ipv4,如果支持ipv6,则可以为all 
inet_protocols = ipv4 
# 164行: 添加 
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 
# 264行: 取消注释,指定内网和本地的IP地址范围 
mynetworks = 127.0.0.0/8
# 419行: 取消注释,邮件保存目录
 home_mailbox = Maildir/ 
# 571行: 添加 
smtpd_banner = $myhostname ESMTP 
# 添加到最后 
# 规定邮件最大尺寸为10M 
message_size_limit = 10485760 
# 规定收件箱最大容量为1G 
mailbox_size_limit = 1073741824 
# SMTP认证 
smtpd_sasl_type = dovecot 
smtpd_sasl_path = private/auth 
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous 
smtpd_sasl_local_domain = $myhostname 
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject 

开启postfix服务并添加到系统自启
systemctl restart postfix
systemctl enable postfix

安装dovecot

yum install dovecot

配置dovect

vim /etc/dovecot/dovecot.conf

更改内容:

# 26行: 如果不使用IPv6,请修改为* 
listen = *
#在主配置文件中的第48行,设置允许登录的网段地址,也就是说我们可以在这里限制只有来自于某个网段的用户才能使用电子邮件系统。如果想允许所有人都能使用,则不用修改本参数
login_trusted_networks = 192.168.10.0/24更改内容

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

更改内容:

# 9行: 取消注释并修改 disable_plaintext_auth = no 
# 97行: 添加 auth_mechanisms = plain login 

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

更改内容:

# 30行: 取消注释并添加 mail_location = maildir:~/Maildir

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

更改内容:

# 88-90行: 取消注释并添加 # Postfix smtp验证 
unix_listener /var/spool/postfix/private/auth { 
mode = 0666 
user = postfix
group = postfix
}
注意:如果我们没有使用ssl的话需要进行下面的操作。使用了则不需要。

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

更改内容

# 8行: 将ssl的值修改为 ssl = no
启动dovecot并添加到开机自启

systemctl restart dovecot
systemctl enable dovecot

邮件的用户是和系统用户一致的,也就是说系统用户可以当做邮件用户。

创建用户并设置密码
useradd admin
passwd admin

mail日志
/var/log/maillog

连接smtp失败

mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
cd /root/.certs

# /etc/mail.rc
#set from=自己的[email protected] 
#set smtp=smtp.qq.com 
#set smtp-auth-user=自己的QQ
#授权码
#set smtp-auth-password=自己的授权码
#set smtp-auth=login
#set smtp-use-starttls set ssl-verify=ignore
#set nss-config-dir=/root/.certs

猜你喜欢

转载自blog.csdn.net/hanxinkong/article/details/85803745