在shell脚本中通过sendmail做邮件通知发送
时间:2008-11-10 来源:jody1212
- #param $1 the file name that contain message to send
- #param $2 message title
- #param $3 to mail box
- #param $4 from mail box
- function do_send_mail()
- {
- local emailname=$3
- local email=$3
- local fromname=$4
- local from=$4
- local subject=$2
- local messagebody=$1
- echo -e "To: \"${emailname}\" <${email}>\nFrom: \"${fromname}\" <${from}>\nSubject: ${subject}\n\n`cat ${messagebody}`" | /usr/sbin/sendmail -t
- }
比如我要将以[email protected]的身份将消息 hello 发送给 [email protected],可以像下面这样使用。
- echo "hello" > /tmp/tmpmail.tmp
- do_send_mail /tmp/tmpmail.tmp hello [email protected] [email protected]
- rm /tmp/tmpmail.tmp
相关阅读 更多 +