【问题标题】:Cid in images not working while sending mail with inline images发送带有内联图像的邮件时,图像中的 Cid 不起作用
【发布时间】:2018-05-31 09:18:02
【问题描述】:
我有一个邮件正文,内嵌图片设置如下:
<img src="cid:<<content-id>>">
我正在使用nodemailer 发送邮件。我还有一个图像的相对 URL。但图像未显示在 Outlook 中。似乎cid 不适用于最新版本的 Outlook。
其他选项?
是否可以在nodejs中获取图像的base64。我已经看到了 canvas 和 xmlhttprequest 的示例,但是如果不使用我不想使用的外部模块,则无法在节点中完成。
请问有什么解决办法吗?
【问题讨论】:
标签:
node.js
base64
nodemailer
inline-images
【解决方案1】:
举个例子,如果你的html属性是:
<p><img src="cid:c001" /></p>
那么attachments 属性必须如下:
[ { path: "data:image/gif;base64,...image data here....",
cid: "c001"
} ]
对于其他嵌入图像,只需将它们添加到 attachments 数组即可。
上面会生成邮件如下:
Content-Type: multipart/alternative; boundary="s1"
--s1
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
...the (plain)`text` part of your message
--s1
Content-Type: multipart/related; type="text/html"; boundary="s2"
--s2
Content-Type: text/html
<p><img src="cid:c001" /></p>
--s2
Content-Type: image/gif; name=attachment-1.gif
Content-ID: <c001>
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=attachment-1.gif
...image data here....
--s2
--s1