CentOS如何发送邮件

CentOS是一个非常不错的免费开源Linux系统,许多站点首选的平台。然而CentOS默认不能发送邮件,需要发送邮件的童鞋可以安装一个sendmail程序。

安装sendmail

执行:

yum -y install sendmail

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

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

[root@vps478753 ~]# service sendmail start
Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]

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

通过文件内容发送邮件

首先创建一个body.txt

touch body.txt

写入内容

echo 'This is test mail' > body.txt

发送邮件

mail -s 'Test mail' xx@xx.com < body.txt

不一会就收到邮件了,正文内容就是body.txt的内容

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

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

echo "This is test mail" | mail -s 'Test mail' xx@xx.com

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

如果提示mail: command not found

[root@vps478753 ~]# mail -s 'Test mail' mail@lizhong.me < body.txt 
-bash: mail: command not found

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

yum install mailx -y

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

分享

TITLE: CentOS如何发送邮件

LINK: https://www.qttc.net/174-centos-send-mail.html

NOTE: 原创内容,转载请注明出自琼台博客