CentOS是一个非常不错的免费开源Linux系统,许多站点首选的平台。然而CentOS默认不能发送邮件,需要发送邮件的童鞋可以安装一个sendmail程序。
安装sendmail
执行:
|
1
|
[root@vps478753 ~]# yum -y install sendmail |
程序会自动搜索出sendmail安装程序自动安装。
安装好sendmail以后执行以下命令启动sendmail
|
1
2
3
|
[root@vps478753 ~]# service sendmail startStarting sendmail: [ OK ]Starting sm-client: [ OK ] |
启动以后我们可以执行mail命令测试一下是否能发送邮件
一、通过文件内容发送邮件
首先创建一个body.txt
|
1
|
[root@vps478753 ~]# touch body.txt |
写入内容
|
1
|
[root@vps478753 ~]# echo 'This is test mail'>body.txt |
发送邮件
|
1
|
[root@vps478753 ~]# mail -s 'Test mail' mail@lizhong.me < body.txt |
不一会就收到邮件了

点击打开,正文内容就是body.txt的内容
This is test mail
二、使用管道符直接发送邮件内容
如果不想通过文件发送邮件内容也可以这么发送
|
1
|
[root@vps478753 ~]# echo "This is test mail" | mail -s 'Test mail' mail@lizhong.me |
以上效果同文件发送邮件内容一样
如果提示mail: command not found
|
1
2
|
[root@vps478753 ~]# mail -s 'Test mail' mail@lizhong.me < body.txt -bash: mail: command not found |
那么就是没有安装mail命令,此时需要安装mail命令
|
1
|
[root@vps478753 ~]# yum install mailx -y |
然后再重新发送以下邮件就好了!
浙公网安备 33010602011771号