bash 使用“mutt”将 Html 页面作为电子邮件发送

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6805783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 20:47:20  来源:igfitidea点击:

Send Html page As Email using "mutt"

bashmutt

提问by eldorado0o

I have been using mutt to send emails from inside another application & it works fine. I have to send html files and currently I have to send them as attachments. So I use

我一直在使用 mutt 从另一个应用程序内部发送电子邮件,它工作正常。我必须发送 html 文件,目前我必须将它们作为附件发送。所以我用

mutt -s "hi" -a attach.html [email protected] < /dev/null

But if I try to send the html file as the body as follows

但是,如果我尝试将 html 文件作为正文发送,如下所示

mutt -e content_type=text/html Email address -s "subject" < test.html

then instead of the html file i get the source text of the html file.

然后我得到了 html 文件的源文本而不是 html 文件。

Is there any way that I can make the body of the message as html instead of plain text???

有什么办法可以将消息正文设为 html 而不是纯文本???

回答by vstm

When I try your command, mutt is telling me that content_type=text/htmlis an unknown command. So you have to use the "set" command to make this work:

当我尝试你的命令时,mutt 告诉我这content_type=text/html是一个未知的命令。所以你必须使用“set”命令来完成这项工作:

mutt -e "set content_type=text/html" Email address -s "subject" < test.html

That worked in my tests.

这在我的测试中有效。

回答by Kevin Zhu

I tried with mutt 1.6d and that option -e "set content_type=text/html" doesn't work for me. After search around i found below command line works for me:

我尝试了 mutt 1.6d 并且该选项 -e "set content_type=text/html" 对我不起作用。在四处搜索后,我发现以下命令行对我有用:

mutt -e "my_hdr Content-Type: text/html" [email protected]  -s "subject" < mytest.html

Reference here

参考这里

LinuxQuestions

Linux问题

回答by YYGCui

my mutt version is 1.4.x, and I also cannot set content_type=text/html, it is reported as unknown variable.

我的 mutt 版本是 1.4.x,我也不能设置 content_type=text/html,它被报告为未知变量。

and I checked the mutt doc, the content_typeis only supported by version 1.5.x, such as the latest version 1.5.21.

我检查了mutt doccontent_type仅受版本 1.5.x 支持,例如最新版本 1.5.21。

obviously, html mail was not supported by version 1.4.x.

显然,1.4.x 版不支持 html 邮件。

回答by Muxiang Yang

I use Mutt 1.5.23 to send an html email with embedded image, and this works for me. mutt -e "set content_type=text/html" Email -s "subject" -a pic.png < test.html

我使用 Mutt 1.5.23 发送带有嵌入图像的 html 电子邮件,这对我有用。 mutt -e "set content_type=text/html" Email -s "subject" -a pic.png < test.html

file test.html:

文件 test.html:

<html>

<head></head>

<body>
  <img src="cid:pic.png" " />
</body>
</html>

回答by glenn Hymanman

If you look at the source of an HTML email, you'll see at minimum something like:

如果您查看 HTML 电子邮件的来源,您至少会看到如下内容:

Subject: test html mail
From: [email protected]
To: [email protected]
Content-Type: multipart/alternative; boundary=bcaec520ea5d6918e204a8cea3b4

--bcaec520ea5d6918e204a8cea3b4
Content-Type: text/plain; charset=ISO-8859-1

*hi!*

--bcaec520ea5d6918e204a8cea3b4
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<p><b>hi!</b></p>

--bcaec520ea5d6918e204a8cea3b4--

So, you have to create a "Content-Type:" header, and add the boundaries above the text-only version, and above and below the HTML version.

因此,您必须创建一个“Content-Type:”标题,并在纯文本版本上方以及 HTML 版本上方和下方添加边界。

Given the amount of hand-crafting required, you might as well hand the message over to sendmail instead of mutt.

鉴于所需的手工制作量,您不妨将消息交给 sendmail 而不是 mutt。