sendEmail下载地址:http://caspian.dotconf.net/menu/Software/SendEmail/ wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz //下载1.56版本tar -xzvf sendEmail-v1.56.tar.gz //解压后就可以使用了mv sendEmail /usr/local/bin/
shell 脚本:
#!/bin/bash
# Date: 2016/12/12
# Author: liang_baikai
touch /tmp/liang_baikai.log
chown zabbix:zabbix /tmp/liang_baikai.log
LOGFILE="/tmp/liang_baikai.log"
:>"$LOGFILE"
exec 1>"$LOGFILE"
exec 2>&1
SMTP_server='smtp.126.com'
username='zxssoft@126.com'
password='zxs19801120'
from_email_address='zxssoft@126.com'
to_email_address="$1"
message_subject_utf8="$2"
message_body_utf8="$3"
message_subject_gb2312=`iconv -t GB2312 -f UTF-8 << EOF
$message_subject_utf8
EOF`
[ $? -eq 0 ] && message_subject="$message_subject_gb2312" || message_subject="$message_subject_utf8"
message_body_gb2312=`iconv -t GB2312 -f UTF-8 << EOF
$message_body_utf8
EOF`
[ $? -eq 0 ] && message_body="$message_body_gb2312" || message_body="$message_body_utf8"
sendEmail='/usr/local/bin/sendEmail'
set -x
$sendEmail -s "$SMTP_server" -xu "$username" -xp "$password" -f "$from_email_address" -t "$to_email_address" -u "$message_subject" -m "$message_body" -o message-content-type=text -o message-charset=gb2312