一、 基于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邮件发送完毕。
邮件虽成功发送,收件人并不一定能看见邮件,因为邮件可能会被视为垃圾邮件而遭到拦截。