CentOS系统安装sendmail 进行邮件发送

1,967次阅读
没有评论

CentOS是VPS百科最喜欢用的Linux系统,也是很多相关教程的基准系统。然而CentOS默认不能发送邮件,需要发送邮件的童鞋可以安装一个sendmail程序。

安装sendmail

执行:

yum -y install sendmail

程序会自动搜索出sendmail安装程序自动安装。

安装好sendmail以后执行以下命令启动sendmail

service sendmail start

启动以后我们可以执行mail命令测试一下是否能发送邮件

一、通过文件内容发送邮件

首先创建一个body.txt

# touch body.txt

写入内容

echo 'This is test mail'>body.txt

发送邮件

mail -s 'Test mail' [email protected] < body.txt

不一会就收到邮件了

点击打开,正文内容就是body.txt的内容

This is test mail

二、使用管道符直接发送邮件内容

如果不想通过文件发送邮件内容也可以这么发送

echo "This is test mail" | mail -s 'Test mail' [email protected]

以上效果同文件发送邮件内容一样

如果提示mail: command not found

-bash: mail: command not found

那么就是没有安装mail命令,此时需要安装mail命令

yum install mailx -y

然后再重新发送以下邮件就好了!

特别注意,如果安装了防火墙,请添加如下规则:

iptables设定

iptables -A INPUT -p tcp --dport 25 -j ACCEPT

iptables -A INPUT -p udp --dport 25 -j ACCEPT

sendmail常见命令

1、查看处理中的邮件

/usr/lib/sendmail -bp

2、清除未发送成功邮件

rm -rf /var/spool/mqueue/*

sendmail服务开机启动设置

chkconfig --level 35 sendmail on

开机启动命令。

正文完
 1
VPS百科小编
版权声明:本站原创文章,由 VPS百科小编 2021-01-23发表,共计824字。
转载说明:
评论(没有评论)