FreeNAS Code
This project has moved to github - see https://github.com/freenas
Brought to you by:
cochard,
mattolander
# Copyright (c) 2008-2010 Volker Theile (votdev@gmx.de) # All rights reserved. # # # Subroutines for email support in scripts. # Requires that rc.conf be loaded first. # . /etc/configxml.subr # send_email [to] [subject] [message] # Send an email. # Return 0 if successful, nonzero otherwise. # $1 - Recipients # $2 - Subject # $2 - Message send_email() { local _recipients _subject _message _rfcdate _result _recipients=$1 _subject=$2 _message=$3 # Get date in RFC 2882 format. _rfcdate=`date "+%a, %d %b %Y %H:%M:%S %z"` # Substitute special characters in subject. _subject=$(echo ${_subject} | sed "s/%h/$(hostname)/" | sed "s/%d/$(date)/") # Create message echo ${_recipients} | awk '{for ( i = NF ; i > 0 ; --i ) printf("To: %s\n",$i)}' > ${msmtp_msgfile} /usr/local/bin/xml sel -t \ -v "concat('From: ',//system/email/from)" -n \ -o "Subject: ${_subject}" -n \ -o "Date: ${_rfcdate}" -n \ -n \ ${configxml_file} | /usr/local/bin/xml unesc >> ${msmtp_msgfile} echo "${_message}" >> ${msmtp_msgfile} # Now email the message to the user /usr/local/bin/msmtp --file=${msmtp_config} ${_recipients} < ${msmtp_msgfile} 1>/dev/null 2>&1 _result=$? # Cleanup /bin/rm ${msmtp_msgfile} 1>/dev/null 2>&1 return ${_result} }