其他分享
首页 > 其他分享> > Mailx发送html消息

Mailx发送html消息

作者:互联网

参见英文答案 > Sending HTML mail using a shell script                                    11个
>            How do I send a file as an email attachment using Linux command line?                                    26个
我想用Mailx发送一条HTML消息.当我尝试以下命令时

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

我以纯文本格式获取了email.html的内容.在消息中,标题Content-Type设置为text / plain. -a选项尝试发送文件,因此我没有找到如何修改标头.这个answer几乎可以工作,它将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.当我尝试在网络邮件中显示消息时,我得到一个空白页面…

解决方法:

如果您的mailx命令支持-a(追加标题)选项,这很容易:

$mailx -a 'Content-Type: text/html' -s "my subject" user@gmail.com < email.html

如果没有,请尝试使用sendmail

# create a header file
$cat mailheader
To: user@gmail.com
Subject: my subject
Content-Type: text/html

# send
$cat mailheader email.html | sendmail -t

标签:html,linux,email,mailx
来源: https://codeday.me/bug/20190916/1807429.html