【发布时间】:2018-07-23 15:13:44
【问题描述】:
按照这个https://stackoverflow.com/a/11725308/1507546,我可以发送一封带有附件的电子邮件。
然而身体总是空的。
notify() {
local mailpart="$(uuidgen)"
local mailpartBody="$(uuidgen)"
local subject="subject"
local attachment='tmp/attachment.txt'
(
echo "From: no-reply@company.com"
echo "To: ${authors}"
echo "Subject: ${subject}"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"${mailpart}\""
echo ""
echo "--${mailpart}"
echo "Content-Type: multipart/alternative; boundary=\"${mailpartBody}\""
echo ""
echo "--${mailpartBody}"
echo "Content-Type: text/plain; charset=ISO-8859-1"
echo "You need to enable HTML option for email"
echo "--${mailpartBody}"
echo "Content-Type: text/html; charset=ISO-8859-1"
echo "Content-Disposition: inline"
echo "<h1>hello world!!</h1>"
echo "--${mailpartBody}--"
echo "--${mailpart}"
echo 'Content-Type: text/plain; name="'$(basename ${attachment})'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename ${attachment})'"'
echo ""
uuencode ${attachment} $(basename ${attachment})
echo "--${mailpart}--"
) | sendmail -t
}
为什么我的函数发送的邮件正文为空,如何解决?
【问题讨论】:
-
为什么是
echo而不是cat <<-EOMail? -
@F.Hauri 你完全正确。这是来自stackoverflow.com/a/11725308/1507546 的快速复制/粘贴,对我不起作用。清洁它是下一步:)