您的位置:首页 > 运维架构 > Linux

Linux邮件通知

2016-07-16 11:39 721 查看
运维部门在对系统进行监控的时候,都需要有邮件告警功能,但是像过去的cacti就没有这样的功能。

通过linux的mail命令可以向内部或外部发送邮件。
mail的发送方式:
1 echo "邮件内容" | mail -s "邮件标题" 收件方地址
2 将邮件内容以文件形式保存
mail -s "邮件标题" 邮箱地址 < 邮件内容文件

发送邮件至系统本地账户:
echo "root_status" | mail -s "root" root@localhost

tail /var/spool/mail/root
Subject: root
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20160716033534.B9B354EAA@ob_web01.localdomain>
From: root@localhost.localdomain (root)

root_status

通过外部smtp发送(以163为例)
1 申请外部邮箱user@163.com
2 确认163的smtp信息




2 配置/etc/mail.rc,增加以下内容

#send the mail from who
set from=user@163.com (邮件发送方)
# setsmtp=smtp://smtp.server.tld:port_number
set smtp=smtp.163.com(smtp服务器信息)
# tell mailx that it needs to authorise
set smtp-auth=login(身份认证方式)
# set the user for SMTP
# set smtp-auth-user=user@domain.tld
set smtp-auth-user=user@163.com(申请的邮箱账户)
# set the password for authorisation
set smtp-auth-password=mailchina654(申请的邮箱密码)

3 测试
邮件标题与内容要谨慎,否则很容易被认为是垃圾邮件,出现以下错误:
echo "hello clark" | mail -s "hello" 5xxxxxxxx@qq.com
[root@localhost]# smtp-server: 554 DT:SPM 163 smtp4,DtGowAAnnBinqIlXp0ohAA--.4861S2 1468639399,please see http://mail.163.com/help/help_spam_16.htm?ip=112.81.40.212&hostid=smtp4&time=1468639399 "/root/dead.letter" 0/0
. . . message not sent.


修改邮件标题和内容后再次测试:
echo "network--clark" | mail -s "network status" 5xxxxxxxx@qq.com




可以收到,测试成功。

163企业退信错误信息查看网址: http://help.163.com/09/1224/17/5RAJ4LMH00753VB8.html
本文出自 “Clark的运维” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: