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: balbal@mail.com";
echo "Subject: subject";
#echo "Content-Type: text/html";
echo "Content-Type: multipart/mixed; boundary=MAIL_BOUNDARY"
echo "MIME-Version: 1.0";
echo $message
cat myHtml.html
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
  • usually one uses mutt or something that understands MIME
    – thrig
    Jan 3, 2018 at 15:07

1 Answer 1


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;

Content-Type: multipart/alternative;

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


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

cat myHtml.html

cat << --OEF--


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

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

) |  sendmail -f 'xxxx@mail.com' balbal@mail.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.