Bash脚本发送包含附件、正文和主题的电子邮件 [英] Bash script sending an e-mail with attachment, body and subject
本文介绍了Bash脚本发送包含附件、正文和主题的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在执行一个MySQL数据库备份脚本,我希望它通过电子邮件向我报告。
到目前为止,我能够做到有一个主体和一个没有依恋的身体。代码:
cat << EOF | mail -s "MySQL backups for $(date +%d.%m.%Y %H:%M)" mymail@mydomain.com
'text in the body'
text outside of the quotes
$value
EOF
我还可以单独发送有主题和附件的电子邮件,但没有正文。代码:
gzip -c test.sh | uuencode test.sh.gz | mail -s "MySQL backups for $(date +%d.%m.%Y %H:%M)" mymail@mydomain.com
当我尝试将它们组合如下时,我收到了一封正文为空的电子邮件。
cat << EOF | gzip -c test.sh | uuencode test.sh.gz | mail -s "MySQL backups for $(date +%d.%m.%Y %H:%M)" mymail@mydomain.com
'text in the body'
text outside of the quotes
$value
EOF
推荐答案
在管道命令中,您使用附件编码覆盖邮件正文。
尝试如下所示:
cat << EOF | mail -s "MySQL backups for $(date +%d.%m.%Y %H:%M)" mymail@mydomain.com
'text in the body'
text outside of the quotes
$value
$(gzip -c test.sh | uuencode test.sh.gz)
EOF
这篇关于Bash脚本发送包含附件、正文和主题的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文