问题
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
回答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.
来源:https://stackoverflow.com/questions/33470547/send-html-message-with-attachement-pdf-from-shell