bash linux 邮件添加内容类型标头不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22457922/
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-18 09:56:17  来源:igfitidea点击:

linux mail adding content type headers not working

linuxbashshellmailx

提问by ??q?? zo???

i am using mailcommand to send mails from my linux system.

我正在使用邮件命令从我的 linux 系统发送邮件。

The problem i am getting is the Content type of the mail is always as Content-Type: text/plain; charset=us-ascii.

我遇到的问题是邮件的内容类型始终为Content-Type: text/plain; charset=us-ascii.

I am sending the html content and it is displaying as plain text.

我正在发送 html 内容,它显示为纯文本。

This is what i have tried

这是我尝试过的

1)
body="From: [email protected]
To: [email protected]
Subject: MIME Test
Mime-Version: 1.0
Content-Type: text/html

<html>
<body>
This is a test.
</body>
</html>";

echo $body| mail -s "testing purpose" [email protected]

this didn't worked

这没有用

i put this html in a file called test.html in $tempfile and tried to execute like this

我将此 html 放在 $tempfile 中名为 test.html 的文件中,并尝试像这样执行

2)
mail -a 'MIME-Version: 1.0' -a 'Content-Type: text/html; charset=iso-8859-1' "server details" "[email protected]" < $tempfile

But nothing has worked, please suggest me regarding this (please only using mail not sendmail/mutt).

但是没有任何效果,请就此向我提出建议(请仅使用邮件而不是 sendmail/mutt)。

回答by deimus

Try

尝试

echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" [email protected]

How to send HTML email using linux command line

如何使用 Linux 命令行发送 HTML 电子邮件