安装sendMail
yum -y install sendmail
1.使用管道进行邮件发送
[root@ProxyServer ~]# echo "hello,echo"|mail -s "echo" justin@51cto.com
2.使用外部smtp(qq的SMTP)来发送邮件
bin/mail会默认使用本地sendmail发送邮件,这样要求本地的机器必须安装和启动Sendmail服务,而通过修改配置文件/etc/mail.rc(/etc/nail.rc)可以使用外部SMTP服务器,可以达到不使用sendmail而用外部的smtp服务器发送邮件的目的。
[root@ProxyServer ~]# vim /etc/mail.rc #文末添加以下
set from=justin@51cto.com
set smtp=smtp.51cto.com
set smtp-auth-user=justin@51cto.com
set smtp-auth-password=51cto
set smtp-auth=login
[root@ProxyServer ~]# source /etc/mail.rc
[root@ProxyServer ~]# mail -s "51cto" 15001*****@139.com < /etc/passwd