0

I understood how I can send a HTML message with sendmail doing:

(
echo "From: me@example.com";
echo "To: you@example.com";
echo "Subject: this is my subject";
echo "Content-Type: text/html";
echo "MIME-Version: 1.0";
echo "";
echo "My <b>HTML message<\b> goes here!";
) | sendmail -t

I also manages to send an attachement with mail doing

uuencode file.pdf file.pdf | mail -s "my subject" you@example.com

but I fail to send an HTML message with an attachement (.pdf).

Note that I failed to install mutt or mpack (using homebrew) so far so I would love a solution that works with mail, mailx or sendmail. I am on Mac OS X 10.11

Remi.b
  • 17,389
  • 28
  • 87
  • 168
  • 1
    Possible duplicate of [Bash: Sending HTML with an attached file?](http://stackoverflow.com/questions/10479340/bash-sending-html-with-an-attached-file) – tripleee Nov 02 '15 at 06:44
  • My question is indeed a duplicate. I am voting to close. Thank you! – Remi.b Nov 03 '15 at 18:15

1 Answers1

1

What you need to do is use multipart mime.

Your Content-Type should be something like:

Content-Type: multipart/mixed; boundary=multipart-boundary

Your multipart-boundary can be any string you like. Then you output a line "--multipart-boundary" followed by headers, then body for each part.

For example:

--multipart-boundary
Content-Type: text/html

My <b>HTML message<\b> goes here!
--multipart-boundary
Content-Type: application/pdf
Content-Disposition: attachment; filename=file.pdf
Content-Transfer-Encoding: base64

**cat your base64 encoded file here **

--multipart-boundary--

The extra two dashes at the end mark the end of last part. You can add as many attachments as you like.

Tony the Tech
  • 570
  • 6
  • 16
  • While your answer is technically correct, getting the OP to piece together a correct MIME message using only shell script is probably not the way to go. Try e.g. http://stackoverflow.com/questions/28954692/mail-command-from-bash-script-not-sending-attachment-when-using-uuencode-mail instead. – tripleee Nov 02 '15 at 06:51
  • Thanks for your answer. I will follow [this](http://stackoverflow.com/questions/10479340/bash-sending-html-with-an-attached-file) solution though as it is easier. – Remi.b Nov 03 '15 at 18:16