[root@iot-svndata02 bin]# cat zbmail.sh #!/bin/bash to_email_address="$1" # 收件人Email地址,zabbix传入的第一个参数 message_subject_utf8="$2" # 邮件标题,zabbix传入的第二个参数 message_body_utf8="$3" # 邮件内容,zabbix传入的第三个参数 set -x # 转换邮件标题为GB2312,解决邮件标题含有中文,收到邮件显示乱码的问题。 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" # 转换邮件内容为GB2312 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/bin/sendmail' #$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 echo "$message_body" |mail -s "$message_subject" "$to_email_address" --content-type=text --encoding=utf-8 set +x #/usr/bin/sendEmail -o message-charset=utf8 -f cloudservice@haierubic.com -t $1 -s mail.haierubic.com -u "$2" -xu cloudservice -xp t2vwN4JXPO -m "$3" time=`date +"%Y-%m-%d"` #echo "`date` $1 $2">>/var/log/zabbix/zbx_mail-$time.log [root@iot-svndata02 bin]#