Bash 脚本发送 e-mail 附件,body 和主题

Bash script sending an e-mail with attachment, body and subject

我正在做一个 MySQL 数据库备份脚本,我希望它通过 e-mail 向我报告。

到目前为止,我能够让它拥有一个主题和一个没有附件的 body。代码:

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

与上述不同,我还能够发送带有主题和附件的 e-mail,但没有 body。代码:

gzip -c test.sh | uuencode test.sh.gz | mail -s "MySQL backups for $(date +%d.%m.%Y\ %H:%M)" mymail@mydomain.com

当我尝试如下组合它们时,我收到一个 e-mail 和一个空的 body。

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