Linux Bash 脚本 - 发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9225585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash script - sending email
提问by Colin747
I'm trying to send an email from a bash script but when I run the script it completes without any errors but the email doesn't seem to be sending (it doesn't arrive in my inbox at least)
我正在尝试从 bash 脚本发送一封电子邮件,但是当我运行该脚本时,它完成了没有任何错误,但电子邮件似乎没有发送(它至少没有到达我的收件箱)
SUBJECT="SET-EMAIL-SUBJECT"
EMAIL="[email protected]"
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`
Thanks
谢谢
采纳答案by glenn Hymanman
Aside from the limitation that what you're trying to do has been blocked, your error is the backticks on the last line of your script. /bin/mail
is a command just like echo
. What you're trying to do is to execute the mail command and then execute the outputof the mail command.
除了您尝试执行的操作被阻止的限制之外,您的错误是脚本最后一行的反引号。/bin/mail
是一个命令,就像echo
. 您要做的是执行邮件命令,然后执行邮件命令的输出。
回答by Badiane
I created a function which I used in a script. You may vary it as you wish.
我创建了一个在脚本中使用的函数。你可以随心所欲地改变它。
send_mail(){
printf "<what you want to say> %s <what you want to say> %d \n" <another function> <another function>| ${MAIL} -s "${SBJCT}" ${EMAIL}
}
Where:
在哪里:
MAIL=`which mail`