Mailx 发送 html 消息 [英] Mailx send html message

查看:41
本文介绍了Mailx 发送 html 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to send a html message with Mailx. When I try the following command

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

我以纯文本格式获取 email.html 的内容.在消息中,标题 Content-Type 设置为 text/plain.-a 选项尝试发送文件,所以我没有找到如何修改标题.这个 answer 几乎有效,它设置了 Content-Type到 text/html 但不替换默认的 Content-Type,即 text/plain.

I get the content of email.html in plain text. In the message the header Content-Type is set to text/plain. The -a option tries to send a file so I didn't find out how to modify the header. This answer almost worked, it sets well the Content-Type to text/html but doesn't substitute the default Content-Type which is text/plain.

mailx -s "$(echo -e "This is the subject
Content-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.当我尝试在网络邮件中显示消息时,我得到一个空白页面...

PS : I also tried with uuencode. When I try to display the message in the webmail I get a blank page...

推荐答案

这很简单,如果您的 mailx 命令支持 -a(附加标题)选项:

It's easy, if your mailx command supports the -a (append header) option:

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

如果没有,请尝试使用 sendmail:

If it doesn't, try using 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

这篇关于Mailx 发送 html 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆