Mailx发送html消息

我想用Mailx发送html消息。当我尝试以下命令时


mailx -s "Subject"  user@gmail.com  < email.html 

我得到纯文本形式的email.html的内容。在消息中,标题Content-Type设置为text / plain。-a选项尝试发送文件,因此我不知道如何修改标头。这个答案几乎可以用,它可以将Content-Type设置为text / html,但是不能替代默认的Content-Type text / plain。


mailx -s "$(echo -e "This is the subject\nContent-Type: text/html")" user@gmail.com  < email.html

给出这个结果:


From: send@gmail.com

To: user@gmail.com

Subject: This is the subject

Content-Type: text/html

Message-ID: <538d7b66.Xs0x9HsxnJKUFWuI%maikeul06@gmail.com>

User-Agent: Heirloom mailx 12.4 7/29/08

MIME-Version: 1.0

 boundary="=_538d7b66.z5gaIQnlwb1f/AOkuuC+GwF1evCaG/XIHQMbMMxbY6satTjK"


This is a multi-part message in MIME format.


--=_538d7b66.z5gaIQnlwb1f/AOkuuC+GwF1evCaG/XIHQMbMMxbY6satTjK

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

Content-Disposition: inline


<html>

<body>

<p>Helo wolrd</p>

</body>

</html>

PS:我也尝试过使用uuencode。当我尝试在网络邮件中显示消息时,我得到一个空白页...


翻翻过去那场雪
浏览 926回答 3
3回答

动漫人物

很简单,如果您的mailx命令支持-a(append header)选项:$ mailx -a 'Content-Type: text/html' -s "my subject" user@gmail.com < email.html如果不是,请尝试使用sendmail:# create a header file$ cat mailheaderTo: user@gmail.comSubject: my subjectContent-Type: text/html# send$ cat mailheader email.html | sendmail -t

蝴蝶不菲

几年来,我已经在Arch Linux(该-a标志用于附件)上成功使用了以下命令:mailx -s "The Subject $( echo -e "\nContent-Type: text/html" user@gmail.com < email.html这将Content-Type标头附加到主题标头,该标头在最近更新之前一直有效。现在,新行已从-s主题中过滤掉。据推测,这样做是为了提高安全性。现在,我不再依赖于修改主题行,而是使用bash子外壳程序:(&nbsp; &nbsp; echo -e "Content-Type: text/html\n"&nbsp; &nbsp; cat mail.html&nbsp;) | mail -s "The Subject" -t user@gmail.com而且由于我们实际上仅使用mailx的subject标志,所以似乎没有理由不sendmail按照@dogbane的建议切换到:(&nbsp; &nbsp; echo "To: user@gmail.com"&nbsp; &nbsp; echo "Subject: The Subject"&nbsp; &nbsp; echo "Content-Type: text/html"&nbsp; &nbsp; echo&nbsp; &nbsp; cat mail.html) | sendmail -tbash子shell的使用避免了创建临时文件的麻烦。
打开App,查看更多内容
随时随地看视频慕课网APP