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的运维” 博客,转载请与作者联系!
通过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的运维” 博客,转载请与作者联系!
相关文章推荐
- linux——在menuconfig中选择m和 *的区别
- linux菜鸟学习(四)----目录结构
- Linux mv 重命名文件问题
- Linux笔记1(内核版和发行版)
- centos6.5修改本地yum源
- 【视频】Linux高级程序设计01.3命令行选项及参数
- 【视频】 Linux高级程序设计01.2开发平台及Linux环境限制
- Linux文件操作例子
- 【视频】Linux高级程序设计01.1开发工具及gcc gdb
- 做10年Windows程序员与做10年Linux程序员的区别
- 给CentOS6.3 + PHP5.3 安装PHP性能测试工具 XHProf-0.9.2
- linux系统中怎么实现文本界面转化为图形界面?
- 如何隐藏你的 Linux 的命令行历史
- Linux 虚拟内存和物理内存的管理
- 如何让Linux定时任务crond以秒为单位执行(如每隔3秒)
- linux 下的访问目录文件权限
- linux菜鸟学习(三)----find
- Qt error : cannot find -lGL and Linux dependency problems
- Linux Ubuntu14 用户密码设置
- Linux下获取用户主目录的方法分享