
2 つの添付ファイルと HTML 形式の件名を付けたメールを UNIX で送信する必要があります。
私は次のことを実行しました。添付ファイルは取得できますが、メールの本文は取得できません。
#!/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' "… 猫$body 「
これプリントコマンドcat
。走るそれ。
また、フォーマット仕様で使用する場合は\n
、引用符で囲まれた改行や単一の大きな文字列を使用しない方がよいでしょう。
Content-Type: text/plain; charset=\"US-ASCII\"
明らかに、指定された本文部分はtext/plain
として解釈されませんtext/html
。ただし、そのファイルの内容は、そもそも HTML ではありません。