0

我需要从具有 HTML 内容类型的 linux 主机发送邮件,并将文件附加到邮件中。

cat html_mail.txt

To: me@mydomain.com

Subject: Test Mail

Content-Type: text/html; charset="us-ascii"

Content-Disposition: inline

<span style="background-color:green">This is in green</span>

我尝试了以下选项:

mail: 

mail -a attachment_file < html_mail.txt

“mail”命令发送附件,但 html_mail.txt 中的 HTML 内容在邮件中以纯文本形式出现

Execution of the command says "Ignoring headers Content-Type".

sendmail:
cat html_mail.txt |sendmail -t
sendmail sends the html content properly, but I couldn't find an option to send an attachment.
4

1 回答 1

3

使用低级sendmail命令发送“仅 HTML”电子邮件

1) 添加必要的 MIME 标头
( MIME-Version, Content-Type, Content-Transfer-Encoding)

html_mail_file

To: me@mydomain.com
Subject: Test Mail
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7BIT
Content-Disposition: inline

<span style="background-color:green">This is in green</span>

*对于非us-ascii字符集声明8BIT编码。大多数电子邮件服务器都会对“原始”8BIT 编码进行必要的转换。

2) 使用sendmail程序发送

/usr/bin/sendmail -i -t < html_mail_file

或者如果您更喜欢单独保留电子邮件标题

echo | cat email_headers_file - html_file | /usr/bin/sendmail -i -t
于 2013-05-22T11:35:21.743 回答