#! /bin/bash################################################################################# Zabbix extensions (C) 2011-* Joseph Bueno <[email protected]># Published under GNU General Public License version 2 or later.# See LICENSE.txt#-------------------------------------------------------------------------------# Usage:# zext_msmtp.sh <recipient> <subject> <message>## Description:# Uses msmtp to send an email. # This script inserts headers:# From: see FROM variable# To: using <recipient># Date: dynamically computed# Subject: using <subject>## <message> may start with headers, msmtp will seperate them from message body# and put them in message headers section.## It uses an msmtp account as defined in MSMTP_ACCOUNT# Account is defined in /etc/msmtprc# # simple account configuration# ----------------------------# account zabbix# host smtp.example.org# from [email protected]## advanced account setup (authentication + TLS on Gmail)# ------------------------------------------------------# account zabbix# tls on# tls_starttls on# tls_trust_file /etc/ssl/certs/ca-certificates.crt# host smtp.gmail.com# port 587# auth on# from [email protected]# user [email protected]# password ***********# # (from, user and password should be replaced with real values).## Dependencies# It needs msmtp utility# On Debian and Ubuntu:# apt-get install msmtp#################################################################################DEBUG=0if [ $DEBUG -gt 0 ]thenexec 2>>/tmp/zext_msmtp.logset -xfi# Default parametersFROM=‘[email protected]‘MSMTP_ACCOUNT=‘zabbix‘# Parameters (as passed by Zabbix):# $1 : Recipient # $2 : Subject# $3 : Messagerecipient=$1subject=$2message=$3date=`date --rfc-2822`# Replace linefeeds (LF) with CRLF and send messagesed ‘s/$/\r/‘ <<EOF | msmtp --account $MSMTP_ACCOUNT $recipientFrom: <$FROM>To: <$recipient>Subject: $subjectDate: $date$messageEOF
This article is from the "muzinan technical blog" and is not reposted!
Zabbix msmtp (Shell)