且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在电子邮件正文中发送html文件的输出

更新时间:2021-12-31 07:35:32

在21世纪包含图像的正确方法是使用MIME.您的信息基本上应该是

The proper way to include an image in the 21st century is with MIME. Your message should basically be something like

From: you <you@example.net>
To: recipient <victim@example.com>
Subject: well, say something
Mime-Version: 1.0
Content-type: multipart/related; boundary=foo

Often you have something about this being a MIME message here.

--foo
Content-type: text/html; charset=utf-8
Content-transfer-encoding: us-ascii

<html><yada yada><img src="cid:bar"></html>

--foo
Content-type: image/png
Content-id: bar
Content-transfer-encoding: base64

sdflkjsdflkjsdflkjsdflkjsdflksdfl=

--foo--

您也可以尝试使用text/plain文本部分和Content-Disposition: inline作为图像;然后,许多客户将在文字下方显示图片.

You can also try with a text/plain text part and a Content-Disposition: inline for the image; many clients will then display the image below the text.

当然,如果您已经将所有内容都保存在一个HTML文件中(如何处理图像?),则只需将其附加到像mutt这样的现代MUA上,都可以通过简单的命令行来完成.

Of course, if you already have it all in one HTML file (how? with the image?) then just attaching that with a modern MUA like mutt should all be doable with a simple command line.