Linux下使用mail发送邮件

邮件常常是Linux下监控报警手段之一。Linux下的mail命令可以方便,快速的完成发送邮件。下面以CentOS为例

1、安装

2、配置 
vi /etc/mail.rc   在文件尾加上如下配置  (注:因为163的设置相对简单些,以163邮箱为例,QQ邮箱等,其他邮箱因为安全等因素,需要设置的比较多,具体的可以搞下,本文不作重点。QQ邮箱也是可以的)

set [email protected]
set smtp=smtp.163.com
set [email protected]
set smtp-auth-password=邮箱密码
set smtp-auth=login


3、发送邮件测试

# echo "Content" | mail -s "Title" [email protected],[email protected]

4、其他

      mail命令 可以使用查看具体更多的使用方法

    mail --h 

      举例:

     a、无邮件正文  

          # mail -s "Title"  [email protected]

      b、有邮件正文

          #   mail -s "Tile"  abc@qq.com </root/zabbix.txt 

         或者 cat /root/zabbix.txt  | mail -s "Tile"  abc@qq.com

         或者 echo “”Content“  |   mail -s "Tile"  abc@qq.com 

    c 、带附件的邮件

       mail -s "Tile"  abc@qq.com  -a  /root/zabbix.txt  

      

1、安装

2、配置 
vi /etc/mail.rc   在文件尾加上如下配置  (注:因为163的设置相对简单些,以163邮箱为例,QQ邮箱等,其他邮箱因为安全等因素,需要设置的比较多,具体的可以搞下,本文不作重点。QQ邮箱也是可以的)

set [email protected]
set smtp=smtp.163.com
set [email protected]
set smtp-auth-password=邮箱密码
set smtp-auth=login


3、发送邮件测试

# echo "Content" | mail -s "Title" [email protected],[email protected]

4、其他

      mail命令 可以使用查看具体更多的使用方法

    mail --h 

      举例:

     a、无邮件正文  

          # mail -s "Title"  [email protected]

      b、有邮件正文

          #   mail -s "Tile"  abc@qq.com </root/zabbix.txt 

         或者 cat /root/zabbix.txt  | mail -s "Tile"  abc@qq.com

         或者 echo “”Content“  |   mail -s "Tile"  abc@qq.com 

    c 、带附件的邮件

       mail -s "Tile"  abc@qq.com  -a  /root/zabbix.txt  

      

猜你喜欢

转载自www.cnblogs.com/eos666/p/11828645.html
今日推荐