[英]Send email with html body and some attachment with sendmail
Follwing this https://stackoverflow.com/a/11725308/1507546 , I could send an email with one attachment. 跟随此https://stackoverflow.com/a/11725308/1507546 ,我可以发送带有一个附件的电子邮件。
However the body is always empty. 但是,身体始终是空的。
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
}
Why is my function sending emails with empty body and how to fix it? 为什么我的功能发送带有空正文的电子邮件以及如何解决?
I figured it out after playing with the headers, this worked for me. 我在玩了标题之后弄明白了,这对我来说很有效。
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 ""
echo "Content-Type: text/plain; charset=ISO-8859-1"
echo "Content-Disposition: inline"
echo ""
echo "<h1>hello world!!</h1>"
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.