Как я могу отправить почту из клиента unix mutt с html и телом в html?

Мне нужно отправить почту из unix через клиент mutt. Я попытался отправить письмо с телом html:

mutt -e "my_hdr Content-Type: text/html" $userEmail -s "Рабочий процесс — выполнение запроса на этапе: $STGUPPER" ‹ $htmlResultFile

РАБОТАЕТ.

Пытался отправить письмо с вложением html:

mutt -e "my_hdr Content-Type: text/html" -a $htmlResultFile -s "attachment" $userEmail

РАБОТАЕТ!

Но когда я пытаюсь отправить письмо с html-телом и html-приложением, я не могу этого сделать.

mutt -e "установить Content-Type: text/html" $userEmail -a $htmlResultFile -s "attachment" ‹ $htmlResultFile

Я получаю html как вложение, но тело как обычный текст.


person quas0r    schedule 01.07.2013    source источник


Ответы (2)


Я подозреваю, что вам придется изготовить корпус самостоятельно. Обратите внимание, что 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"
person glenn jackman    schedule 02.07.2013

Мне не удалось отправить объединенный обычный текст и HTML в mutt. В итоге я создал электронное письмо вручную и отправил его на sendmail -t.

Пример: https://github.com/kaihendry/sg-hackandtell/blob/master/list/maillist

Это должно дать лучшие результаты, чем просто отправка электронной почты в формате HTML.

person hendry    schedule 07.02.2014