我怀疑你必须自己制作身体。请注意,混合主体的content_type是multipart/alternative
我发现这个问题很有趣。这是我对此采取:
#!/bin/sh
# using mutt, send a mixed multipart text and html message:
usage() {
echo "error: $1"
echo "usage: $(basename $0) -t textfile -h htmlfile -s subject -r recipient"
exit 1
}
textfile=""
htmlfile=""
subject=""
recipient=""
while getopts "t:h:s:r:" opt; do
case $opt in
t) textfile="$OPTARG" ;;
h) htmlfile="$OPTARG" ;;
s) subject="$OPTARG" ;;
r) recipient="$OPTARG" ;;
?) usage "invalid option: -$OPTARG" ;;
esac
done
shift $((OPTIND-1))
[ -z "$textfile" ] && usage "no textfile specified"
[ -z "$htmlfile" ] && usage "no htmlfile specified"
[ -z "$recipient" ] && usage "no recipient specified"
[ ! -f "$textfile" ] && usage "no such file: $textfile"
[ ! -f "$htmlfile" ] && usage "no such file: $htmlfile"
boundary=$(openssl rand -hex 24)
content_type="Content-type: multipart/alternative; boundary=$boundary"
##
body=$(cat - << END
--$boundary
Content-Type: text/plain; charset=ISO-8859-1
$(cat "$textfile")
--$boundary
Content-Type: text/html; charset=ISO-8859-1
$(cat "$htmlfile")
--$boundary
END
)
##
echo "$body" | mutt -e "myhdr $content_type" -s "$subject" "$recipient"