linux邮件通知,Linux邮件通知

运维部门在对系统进行监控的时候,都需要有邮件告警功能,但是像过去的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信息

1a6a112c76eaaaf2b8fc59e8e7f9cad0.png

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=mail65411(申请的邮箱密码)

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.

d5804ab9671d2d2eb3afb4e29980c09b.png

修改邮件标题和内容后再次测试:

echo "network--clark" | mail -s "network status" 5xxxxxxxx@qq.com

f5e0b0a32257e1bc7a0464bab696753c.png

可以收到,测试成功。

163企业退信错误信息查看网址:

http://help.163.com/09/1224/17/5RAJ4LMH00753VB8.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值