从Shell发送带有附件(.pdf)的HTML消息 [英] Send HTML message with attachement (.pdf) from Shell
问题描述
我了解如何使用 sendmail
发送HTML消息:
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
我也设法通过 mail
发送附件
uuencode file.pdf file.pdf | mail -s "my subject" you@example.com
但是我无法发送带有附件(.pdf)的HTML消息.
but I fail to send an HTML message with an attachement (.pdf).
请注意,到目前为止,我(使用自制软件)未能安装 mutt
或 mpack
,所以我希望使用与 mail
兼容的解决方案, mailx
或 sendmail
.我在Mac OS X 10.11上
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
推荐答案
您需要做的是使用multipart mime.
What you need to do is use multipart mime.
您的内容类型应类似于:
Your Content-Type should be something like:
Content-Type: multipart/mixed; boundary=multipart-boundary
您的multipart-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.
例如:
--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
**在这里获取您的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.
这篇关于从Shell发送带有附件(.pdf)的HTML消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!