mailx发送html,Mailx发送html消息

本文介绍如何使用mailx命令行工具发送包含HTML格式的邮件。通过使用-a选项添加自定义头部信息,如Content-Type:text/html,可以使邮件内容以HTML格式正确呈现。如果mailx不支持-a选项,则可以通过创建一个包含必要头部信息的文件并使用sendmail工具来实现相同的目标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

Helo wolrd

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值