[英]Send email with html body and some attachment with sendmail
跟隨此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
}
為什么我的功能發送帶有空正文的電子郵件以及如何解決?
我在玩了標題之后弄明白了,這對我來說很有效。
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.