본문의 sendmail 및 html 형식 관련 문제

본문의 sendmail 및 html 형식 관련 문제

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이 아닙니다.

관련 정보