【问题标题】:How to send mail from linux command line with HTML content body and an attachment [closed]如何从带有 HTML 内容正文和附件的 linux 命令行发送邮件 [关闭]
【发布时间】:2013-05-22 07:48:49
【问题描述】:

我需要从具有 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.

【问题讨论】:

标签: linux email sendmail


【解决方案1】:

使用低级 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

【讨论】:

  • 是的,试过了。没有帮助。谢谢
猜你喜欢
  • 2014-11-18
  • 2019-12-18
  • 1970-01-01
  • 2015-11-27
  • 2013-04-15
  • 2018-11-07
  • 2011-02-05
  • 1970-01-01
相关资源
最近更新 更多