centos7 发送邮件给外部邮箱

1、编辑/etc/mail.rc  文件加入下面几句话

set [email protected] smtp=smtp.163.com

set smtp-auth-user=jiong210  smtp-auth-password=password
set smtp-auth=login

解释:from 为发送邮件的来源

           smtp-auth-user为用户名

          smtp-auth-password为[email protected]的授权密码,并开启pop3/SMTP服务,需要自己在邮箱中设置,如下:


2、经过第一步设置,就可以用mail发送邮件了,其中mail是centos7自带的,无需安装,有3种发送方式

    a.   mail -s "test"    [email protected]  //-s 指的是邮件标题,按enter键输入邮件内容,Ctrl + d 结束输入

   b .   echo "test3" |mail -s "test"    [email protected]    // "test3"指的是文件内容

   c    mail -s "test"    [email protected] < test.sh   //从文件写入邮件内容

当然也可以添加附件,如 echo "test3" |mail -s "test"  -a  test.sh  [email protected]


你可能感兴趣的:(linux运维)