automation 服务器不能创建对象_CentOS7搭建简单的邮件服务器

邮件服务器

概述

邮件收、发服务器是分开的,也就是我们需要搭建一个邮件发送服务器和一个邮件收取服务器。
本文会搭建收、发两个服务器,并用邮件客户端(Foxmail)做测试。

协议

协议就是定义规则,这里是邮件协议,定义邮件收发的规则,了解规则有助于理解软件的配置文件。
邮件发送协议 SMTP(Simple Mail Transfer Protocol),打开端口 25。
邮件收取协议 POP,打开端口 110;还有个常用邮件收取协议 IMOP,打开端口 143。

服务软件

Postfix
Postfix 是实现 SMTP 协议的软件,也叫做邮件发送服务器。

上面说的邮件客户端将邮件扔给它,由它对邮件进行转发,至于怎么转发,SMTP 协议制定了规则,而 Postfix 负责具体事情,我们只需要修改 Postfix 配置文件要求它按照我们的想法去做。

Dovecot
Dovecot 实现了 POP 和 IMOP 协议,也叫做邮件收取服务器。如果只搭建了 Postfix 而没有它,不好意思,你是收不到邮件的。

Sasl
Sasl登陆验证服务,在下面的介绍可以看到 Postfix 作为邮件发送服务器,不能无限制的转发任意邮件,应当只转发它信任的发件人发送的邮件,这一点体现在 Postfix 的配置文件要配置它认为安全的主机(mynetworks 参数)。但这样会显得很麻烦,Sasl 通过其它方式也可以帮助 Postfix 完成信任邮件的认证。

设置域名

mail.52zt.info用A记录解析到邮件服务器IP(后面的各个客户端配置的域名都写这个A记录的),再把52zt.info用MX记录解析到mail.52zt.info(这个是当遇到***@52zt.info时会解析到mail.52zt.info)。
测试端口telnet命令也要用mail.52zt.info,不能用mx记录的52zt.info(用这个会解析到A记录解析的52zt.info)。6acc9477-9519-eb11-8da9-e4434bdf6706.png

安装软件

安装软件postfix、dovecot、cyrus-sasl

yum -y install postfix dovecot  cyrus-sasl

配置软件

配置postfix

vi /etc/postfix/main.cf


myhostname = mail.52zt.info

mydomain = 52zt.info

myorigin = $mydomain

inet_interfaces = all
inet_protocols = all

mydestination = $myhostname,$mydomain

home_mailbox = Maildir/




smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
mynetworks = 127.0.0.0/8
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
  • smtpd_sasl_auth_enable = yes //开启认证

  • smtpd_sasl_security_options = noanonymous //不允许匿名发信

  • mynetworks = 127.0.0.0/8//允许的网段,如果增加本机所在网段就会出现允许不验证也能向外域发信

  • smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

  • 允许本地域以及认证成功的发信,拒绝认证失败的发信

检查并启动postfix

postfix check  
systemctl start postfix
systemctl enable postfix

配置dovecot

vi /etc/dovecot/dovecot.conf

protocols = imap pop3 lmtp
listen = *, ::



!include conf.d/10-auth.conf

ssl = no
disable_plaintext_auth = no
mail_location = maildir:~/Maildir

启动dovecot

systemctl start dovecot    
systemctl enable dovecot

配置cyrus-sasl

vi /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
log_level:3
vi /etc/sysconfig/saslauthd
MECH=shadow

启动

systemctl start saslauthd     
systemctl enable saslauthd

添加用户

添加用户,并将密码设为123456

 useradd  autumn
echo 123456 | passwd --stdin autumn

测试

yum -y install telnet-server telnet

测试发送

[root@mail ~]
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.52zt.info ESMTP Postfix
mail from:autumn@52zt.info
250 2.1.0 Ok
rcpt to:qy814379857@foxmail.com
250 2.1.5 Ok
data
354 End data with .
subject:这是主题
this is test mail
.
250 2.0.0 Ok: queued as 6224C10263A

6bcc9477-9519-eb11-8da9-e4434bdf6706.png

登录邮箱

[root@mail ~]
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user autumn
+OK
pass 密码
+OK Logged in.


list
retr 1
quit

6ccc9477-9519-eb11-8da9-e4434bdf6706.png

用mailx测试

安装

yum  install  mailx -y

使用mailx发送邮件

echo '测试邮件内容' | mail -s '测试主题!' qy814379857@foxmail.com

邮箱客户端配置

Outlook配置

收邮件延迟较高,不推荐使用6dcc9477-9519-eb11-8da9-e4434bdf6706.png

如果出现

服务器错误: '554 5.7.1 Relay access denied'

1,打开outlook,点击  “文件”“信息”bai,进入 “账户设置”。
2,双击账户,进入更改账户。
3,点击 “其他设置”,选择发送服务器选项卡,勾选我的发送服务器要求验证(如果忘记勾选,只能收到邮件却不能发送邮件)6fcc9477-9519-eb11-8da9-e4434bdf6706.png

Foxmail配置

选中设置->账号->定时收取邮件,设置好每隔多少分钟拉取邮件.推荐使用Foxmail.70cc9477-9519-eb11-8da9-e4434bdf6706.png

出现问题

在起好了服务,开放了防火墙端口,设置了安全组的情况下。telnet localhost 25端口通,telnet 域名 25不通,是因为服务监听ip的问题

vi /etc/postfix/main.cf

inet_interfaces=localhost  注释掉这段,上面写了all,没注意这里还有个localhost

参考:
https://www.qcmoke.site/devops/mail.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值