我正在尝试使用具有e-mail
正文和附件的Unix
发送HTML
。
该代码无需附件部分即可工作,但是当我添加附件行时,我收到的邮件只是将所有内容显示为纯文本。
该代码似乎无效,请提供帮助:
MAIL_TO="receiver@mail.com"
MAIL_FROM="sender@mail.com"
MAIL_SUBJECT="MAIL SUBJECT"
ATTACHMENT=sample.txt
HTML_FILE=sample.html
(
echo "From: ${MAIL_FROM}"
echo "To: ${MAIL_TO}"
echo "Subject: ${MAIL_SUBJECT}"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary="MAIL_BOUNDARY";"
echo "Content-Disposition: inline"
echo "--MAIL-BOUNDARY"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat ${HTML_FILE}
echo "--MAIL-BOUNDARY"
echo "Content-Type: text/plain; name="${ATTACHMENT}""
echo "Content-Disposition: attachment; filename="${ATTACHMENT}""
echo "Content-Transfer-Encoding: base64"
base64 ${ATTACHMENT}
echo "--MAIL-BOUNDARY"
) | /usr/sbin/sendmail "${MAIL_TO}"
答案 0 :(得分:0)
您忘了在最后一个MIME边界之后添加结尾close-delimiter。
...
echo "--MAIL_BOUNDARY--"
) | /usr/sbin/sendmail "${MAIL_TO}"