0

This is how I try to send, email with sendmail command.

With html file in body and attached zip file.

The mail received is corrupted (without body and with corrupted attachment) .

(
echo "From: xxxx";
echo "To: [email protected]";
echo "Subject: subject";
#echo "Content-Type: text/html";
echo "Content-Type: multipart/mixed; boundary=MAIL_BOUNDARY"
echo "MIME-Version: 1.0";
 echo "--MAIL_BOUNDARY"
echo $message
cat myHtml.html
echo "--MAIL_BOUNDARY"
echo "Content-Type: application/zip"
echo "Content-Transfer-Encoding: base64"
echo "Content-Disposition: attachment; filename=zipfile.zip"
base64  zipfile.zip
echo "--MAIL_BOUNDARY--"

)> email.body

cat email.body | sendmail -t
1
  • usually one uses mutt or something that understands MIME Commented Jan 3, 2018 at 15:07

1 Answer 1

2

This is how I get messages with attachments out of the door. I have to execute it as root, otherwise senmail refuses a "From:" (-f option) that is not the user sending the mail. I've replaced the echos by cat with here documents.

message="You will find zipfile.zip attached"
(
cat << --OEF--
Subject: $message
MIME-Version: 1.0
Content-Type: multipart/mixed;
  boundary="MAIL_BOUNDARY"


--MAIL_BOUNDARY
Content-Type: multipart/alternative;
  boundary="MAIL_BOUNDARY2"

--MAIL_BOUNDARY2
Content-Type: text/plain; charset=utf-8

$message

--MAIL_BOUNDARY2
Content-Type: text/html; charset=utf-8

--OEF--
cat myHtml.html

cat << --OEF--

--MAIL_BOUNDARY2--

--MAIL_BOUNDARY
Content-Type: application/zip; name=zipfile.zip
Content-Disposition: attachment; filename=zipfile.zip
Content-Transfer-Encoding: base64

--OEF--
base64  zipfile.zip
cat << --OEF--

--MAIL_BOUNDARY--
--OEF--
) |  sendmail -f '[email protected]' [email protected]

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.