我需要从具有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.
答案 0 :(得分:3)
sendmail
命令 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
编码。大多数电子邮件服务器都会对&#34; raw&#34;进行必要的转换。 8BIT编码。
2)使用sendmail
程序
/usr/bin/sendmail -i -t < html_mail_file
或者如果您希望单独保留电子邮件标题
echo | cat email_headers_file - html_file | /usr/bin/sendmail -i -t