常完美的选择:使用简单并且功能强大.这个被设计用在php、bash
perl和web站点使用。以上是sendEmail的简单介绍,千万不要和sendmail搞混掉了。
1、下载sendEmail软件以及解压
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@Server ~]
# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
[root@Server ~]
# tar fxz sendEmail-v1.56.tar.gz
[root@Server ~]
# cd sendEmail-v1.56
[root@Server sendEmail-v1.56]
# ll
total 116
-rw-r--r-- 1 root root 13329 Sep 30 2009 CHANGELOG
-rw-r--r-- 1 root root 7949 Sep 30 2009 README
-rw-r--r-- 1 root root 4701 Sep 30 2009 README-BR.txt
-rwxr-xr-x 1 root root 80213 Sep 30 2009 sendEmail
lrwxrwxrwx 1 root root 9 Apr 29 18:19 sendEmail.pl -> sendEmail
-rw-r--r-- 1 root root 1229 Sep 30 2009 TODO
[root@Server sendEmail-v1.56]
# cp sendEmail /usr/local/bin/
[root@Server sendEmail-v1.56]
# ll /usr/local/bin/sendEmail
-rwxr-xr-x 1 root root 80213 Sep 30 2009
/usr/local/bin/sendEmail
[root@Server sendEmail-v1.56]
# yum install perl-Net-SSLeay perl-IO-Socket-SSL -y
|
2、使用sendEmail测试发送邮件
1
2
3
4
|
[root@Server ~]
# /usr/local/bin/sendEmail -f vip@163.com -t 19672@qq.com \
> -s smtp.163.com -u
"我是邮件主题"
-o message-content-
type
=html \
> -o message-charset=utf8 -xu vip@163.com -xp 123 -m
"我是邮件内容"
Apr 29 22:22:19 server sendEmail[75870]: Email was sent successfully!
|
命令说明:
1
2
3
4
5
6
7
8
9
10
11
|
/usr/local/bin/sendEmail
命令主程序
-f yzkc_vip@163.com 发件人邮箱
-s smtp.163.com 发件人邮箱的smtp服务器
-u
"我是邮件主题"
邮件的标题
-o message-content-
type
=html 邮件内容的格式,html表示它是html格式
-o message-charset=utf8 邮件内容编码
-xu yzkc_vip@163.com 发件人邮箱的用户名
-xp 123 发件人邮箱密码
-m
"我是邮件内容"
邮件的具体内容
发送成功之后会有如下提示:
Apr 29 22:22:19 server sendEmail[75870]: Email was sent successfully!
|
3、进入zabbix自定义的指定目录,在zabbix_server.conf配置文件AlertScriptsPath查看得知
1
2
3
|
[root@Server zabbix]
# mkdir /var/lib/zabbixsrv/externalscripts
[root@Server zabbix]
# mkdir /var/lib/zabbixsrv/alertscripts
[root@Server zabbixsrv]
# chown zabbix.zabbix externalscripts/ -R
|
在/var/lib/zabbixsrv/alertscripts目录下创建脚本为sendEmail.sh,内容如下:
1
2
3
4
5
6
7
8
|
[root@Server alertscripts]
# cat sendEmail.sh
#!/bin/bash
to=$1
subject=$2
body=$3
/usr/local/bin/sendEmail
-f vip@163.com -t
"$to"
-s smtp.163.com -u
"$subject"
-o message-content-
type
=html -o message-charset=utf8 -xu vip@163.com -xp 123 -m
"$body"
[root@Server alertscripts]
# chmod +x sendEmail.sh
[root@Server alertscripts]
# chown zabbix.zabbix /var/lib/zabbixsrv/ -R
|
来源:oschina
链接:https://my.oschina.net/u/4380905/blog/4317302