이메일 첨부 파일이 비어 있습니다.

이메일 첨부 파일이 비어 있습니다.

Sendmail EML 파일에 첨부파일을 추가하려고 합니다. 현재 eml 파일(order.eml)에는 다음과 같은 내용이 있습니다.

From: Sender <[email protected]>
To: [email protected]
Subject: Report
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="B835649000072104Jul07"

--B835649000072104Jul07
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Body Copy

--B835649000072104Jul07
Content-Type: application/pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="por5151.pdf"
base64 por5151.pdf

--B835649000072104Jul07--

order.eml 및 por5151.pdf 파일은 모두 동일한 디렉토리에 있으며 다음을 사용해 보았습니다.

# /usr/sbin/sendmail -t < order.eml

이메일이 도착하면 첨부파일에 por5151.pdf가 보이는데 비어있습니다(0바이트). 왜 이런 일이 발생하는지 모르겠고 고치려고 노력 중입니다.

답변1

당신이해야 할 일은 파일을

Content-Disposition: attachment; filename="por5151.pdf"

파일을 생성할 때 .eml다음 base64유틸리티를 사용하여 이를 수행할 수 있습니다.

base64 por5151.pdf

닫는 테두리( --B835649000072104Jul07--)가 그 뒤에 삽입되었는지 확인하세요.

sendmail전달한 파일은 해석되지 않으므로 파일 내용이 마술처럼 삽입되지 않습니다 .pdf.

답변2

CSV 파일을 추가하기 위해 다음 스크립트를 만들었습니다. CSV의 열 이름이 잘못 잘렸고 이메일을 통해 "ATT0001.txt"라는 다른 파일도 가져왔습니다.

(
echo "From:"$1;
echo "To:"$2;
echo "Subject:"$3;
echo "MIME-Version: 1.0";
echo "Content-Type:multipart/mixed; boundary=\"B835649000072104Jul07\"";

echo "--B835649000072104Jul07";
echo "Content-Type: text/html; charset=\"UTF-8\"";
echo "Content-Transfer-Encoding: 7bit";
echo "Content-Disposition: inline";
echo "";
echo "$4";

echo "--B835649000072104Jul07";
echo "Content-Type: text/csv";
echo "Content-Transfer-Encoding: base64";
echo "Content-Disposition: attachment; filename=\"$5\"";
base64 "$5"

echo "--B835649000072104Jul07";
) | sendmail -t

관련 정보