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

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

问题描述

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

  mailx -sSubjectuser@gmail.com< email.html 

我以纯文本形式收到email.html的内容。在消息中,标题Content-Type设置为text / plain。 -a选项尝试发送文件,因此我没有找到如何修改标题。这个答案几乎工作,它设置好内容类型到text / html,但不能替换默认的Content-Type,它是text / plain。

  mailx -s$(echo -e这是主题\Content-Type:text / html) user@gmail.com< email.html 

给出了这个结果:

  From:send@gmail.com 
至:user@gmail.com
主题:这是主题
内容类型:text / html
Message-ID:< 538d7b66.Xs0x9HsxnJKUFWuI%maikeul06@gmail.com>
用户代理:Heirloom mailx 12.4 7/29/08
MIME版本:1.0
boundary == _ 538d7b66.z5gaIQnlwb1f / AOkuuC + GwF1evCaG / XIHQMbMMxbY6satTjK

这是MIME格式的多部分消息。

- = _ 538d7b66.z5gaIQnlwb1f / AOkuuC + GwF1evCaG / XIHQMbMMxbY6satTjK
内容类型:text / plain; charset = us-ascii
Content-Transfer-Encoding:7bit
内容处理:inline

< html>
< body>
< p> Helo wolrd< / p>
< / body>
< / html>

PS:我也尝试过uuencode。当我尝试在webmail中显示消息时,我得到一个空白页...

解决方案

很容易,如果你的 mailx 命令支持 一个 (追加标题)选项:

  $ mailx -a'Content-Type :text / html'-s我的主题user@gmail.com< email.html 

如果没有,请尝试使用 sendmail

 #创建头文件
$ cat mailheader
To:user@gmail.com
主题:我的主题
内容类型:文本/ html

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


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

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

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\nContent-Type: text/html")" user@gmail.com  < email.html

gives this result :

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 : I also tried with uuencode. When I try to display the message in the webmail I get a blank page...

解决方案

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

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天全站免登陆