正文中的 sendmail 和 html 格式有問題

正文中的 sendmail 和 html 格式有問題

我需要在unix中發送帶有2個附件和html格式主題的郵件。

我做了以下操作,它有助於獲取附件,但對郵件中的正文內容沒有幫助

#!/bin/bash
from="[email protected]"
to="[email protected]"
subject="Status"
boundary="ZZ_/afg6432dfgkl.94531q"
body="mail_body.txt"
attachments=( "FiC.txt" "FiE.txt")

# Build headers
{

printf '%s\n' "From: $from
To: $to
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"$boundary\"

--${boundary}
Content-Type: text/plain; charset=\"US-ASCII\"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

cat $body
"

for file in "${attachments[@]}"; do

  [ ! -f "$file" ] && echo "Warning: attachment $file not found, skipping" >&2 && continue

 #mimetype=$(get_mimetype "$file") 

  printf '%s\n' "--${boundary}
Content-Type: text/html
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$file\"
"

  base64 "$file"
  echo
done

printf '%s\n' "--${boundary}--"

} | /usr/sbin/sendmail -t -oi 

mail_body.txt的內容:

   echo "<html>
        <head>
        <title> Status</title>
        </head>
        "

可以幫助在郵件正文部分列印 html 內容嗎?

答案1

printf '%s\n' "...
貓$身體

印刷命令cat。它不是跑步它。

如果您打算\n在格式規格中使用,則最好不要使用帶有引號的換行符號和單個大字串。

Content-Type: text/plain; charset=\"US-ASCII\"

相當明顯,指定的身體部位text/plain不會被解釋為text/html。儘管該文件的內容(如給定的)首先不是 HTML。

相關內容