Bash脚本 - 发送电子邮件

时间:2012-02-10 09:32:48

标签: linux bash

我正在尝试从bash脚本发送电子邮件但是当我运行脚本时它完成没有任何错误,但电子邮件似乎没有发送(它至少没有到达我的收件箱)

SUBJECT="SET-EMAIL-SUBJECT"
EMAIL="me@address.co.uk"
EMAILMESSAGE="/home/me/workspace/ss/UI/UI/legacy/Output.txt"
echo "This is an email message test">$EMAILMESSAGE
echo "This is a second line">>$EMAILMESSAGE
echo "This is a third line">>$EMAILMESSAGE
# send an email using /bin/mail
`/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE`

由于

2 个答案:

答案 0 :(得分:3)

除了您尝试执行的操作已被阻止的限制之外,您的错误是脚本最后一行的反引号。 /bin/mail是一个与echo类似的命令。你要做的是执行mail命令,然后执行mail命令的输出

答案 1 :(得分:-1)

我创建了一个我在脚本中使用的函数。你可以随意改变它。

send_mail(){
     printf "<what you want to say>  %s <what you want to say>  %d \n" <another function> <another function>| ${MAIL} -s "${SBJCT}" ${EMAIL}
}

其中:

MAIL=`which mail`
相关问题