
Ich muss unter Unix eine E-Mail mit zwei Anhängen und dem Betreff im HTML-Format senden.
ich habe Folgendes getan, es hilft, den Anhang, aber nicht den Textinhalt der E-Mail zu erhalten.
#!/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
Inhalt von mail_body.txt:
echo "<html>
<head>
<title> Status</title>
</head>
"
Kann es hilfreich sein, HTML-Inhalte im Textteil der E-Mail auszudrucken?
Antwort1
printf '%s\n' "… Katze $Körper "
Dasdrucktder cat
Befehl. EslaufenEs.
\n
Und wenn Sie die Formatspezifikation verwenden , können Sie auch gleich auf die in Anführungszeichen gesetzten Zeilenumbrüche und einen einzelnen, langen String verzichten.
Content-Type: text/plain; charset=\"US-ASCII\"
Es ist ziemlich offensichtlich, dass ein bezeichneter Textteil text/plain
nicht als interpretiert wird text/html
. Obwohl der Inhalt dieser Datei, wie angegeben, überhaupt kein HTML ist.