如何在SendGrid动态模板中正确渲染base64格式自定义内嵌图片
问题1:模板中cid引用格式错误
你当前模板的img标签里写的是cid::planmap,多了一个冒号,CID引用的标准格式是单冒号,改为cid:planmap即可。
问题2:附件配置字段冗余冲突
SendGrid官方附件配置中,标识内联图片的唯一标准字段是content_id,你同时配置了cid和content_id两个相同值的字段,可能会触发SendGrid的字段识别异常,删除多余的cid: 'planmap'配置即可。你也可以额外添加disposition: 'inline'字段,明确标识该资源为内联资源,兼容更多邮件客户端。
问题3:base64内容校验
确认emailPlanParams.firstPlan.map的值是纯base64编码内容,不要带data:image/png;base64,这类前缀,否则会导致附件编码错误无法被识别为内联图片。
修复后的附件配置参考:
attachments: [ { content_id: 'planmap', filename: 'plan_map.png', content: emailPlanParams.firstPlan.map, encoding: 'base64', disposition: 'inline' } ]
修复后的模板img标签参考:
<img src="cid:planmap" alt="Plan Map" border="0" align="center" style="width:100%; max-width: 600px; margin-bottom: 20px; height: auto; background: #dddddd;">
内容的提问来源于stack exchange,提问作者Gal Gendler
相关产品推荐
相关产品推荐

