centos8电子邮件服务—1.基于Postfix的邮件发送(超级详细)

一、 基于Postfix的邮件发送

1. 安装并启动postfit

[root@hello ~]# yum -y install postfix
[root@hello ~]# systemctl start postfix
[root@hello ~]# systemctl enable postfix

2. 设置hostname并更新 /etc/hosts

在此我修改为了hello.com,看自己定。修改hosts文件时,在最后一行加入自己的linux的IP

[root@hello ~]# hostnamectl set-hostname hello.com
[root@hello ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.125  hello.com

3. 安装 mailx 邮件客户端

在配置 Postfix 服务器之前,我们需要安装 mailx

[root@hello ~]# yum -y install mailx

4. 配置 Postfix 邮件服务器

Postfix 的配置文件位于 /etc/postfix/main.cf 中。我们需要对配置文件进行一些修改, vim /etc/postfix/main.cf在里面添加

myhostname = mail.hello.com
mydomain = hello.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.10.0/24, 127.0.0.0/8
home_mailbox = Maildir/

完成后,保存并退出配置文件。重新启动 postfix 服务以使更改生效

systemctl restart postfix

5. 测试,使用postfix发送邮件

每条命令执行,终端都返回250,说明命令执行成功。

[root@hello ~]# telnet 0 25
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
220 mail.hello.com ESMTP Postfix
helo main.hello.com         (向服务器表明身份)
250 mail.hello.com
mail from:zhou@hello.com   (设置寄件人)
250 2.1.0 Ok
rcpt to:text@hello.com       (设置收件人)
250 2.1.5 Ok
(设置邮件内容,用data命令编辑邮件内容,以“.”结束)
data
354 End data with <CR><LF>.<CR><LF>
hello word!!!
.
250 2.0.0 Ok: queued as 3B98E64E6B77
quit        (quit时退出telnet命令)
221 2.0.0 Bye
Connection closed by foreign host.

至此,postfix邮件发送完毕。
邮件虽成功发送,收件人并不一定能看见邮件,因为邮件可能会被视为垃圾邮件而遭到拦截。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值