【问题标题】:sendgrid multipart/alternative image from base64来自 base64 的 sendgrid 多部分/替代图像
【发布时间】:2013-07-19 20:05:47
【问题描述】:

我无法让 Sendgrid(使用 node.js)在 html 中发送带有嵌入式 base64 图像的电子邮件。我想我已经很接近了……

var base64img='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQgAAAFXCAYAAABeLtDdAAAgAElEQVR4Xu19CXhURdb2ISsJgSQ';//shortened version

sendgrid.send({
    to      : 'address1@gmail.com',
    from    : 'address2@gmail.com',
    subject : 'email with image from base64 data',
    headers:{
      'Content-Type':
      'multipart/alternative; boundary="imagebase64"'+
      '--imagebase64'+
      'Content-Type: image/png; name="base64.png"'+
      'Content-Disposition: inline; filename="base64.png"'+
      'Content-Transfer-Encoding: base64'+
      'Content-ID: <0123456789>'+
      'Content-Location: base64.png'+
      base64img+
      '--imagebase64'
      },
    html    : '<img src="cid:0123456789"/>'
    });

有人可以帮忙吗,因为我在 sendgrid docs 或 google 上找不到关闭的示例

【问题讨论】:

    标签: sendgrid email-headers


    【解决方案1】:

    已修复!

      var base64img='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQgAAAFXCAYAAABeLtDdAAAgAElEQVR4Xu19CXhURdb2ISsJgSQ';//shortened version
      var data=base64img.replace(/^data:image\/\w+;base64,/,"");
      var buffer=new Buffer(data,'base64');
      fs.writeFile('/home/engine/public_html/img/base64img.png',buffer,function(err){
        fs.readFile('public_html/img/base64img.png',function(err,data){
    
    
        sendgrid.send({
          to      : 'address11@gmail.com',
          from    : 'address2@gmail.com',
          subject : 'email with image from base64 data',
          files   : [{filename:'base64.png',content:data,cid:'1234567890'}],
          html    : '<img src="cid:1234567890"/>'
          },
        function(success,message){
          if(!success){console.log(message);}
          else{
            console.log('sent');
            fs.unlink('public_html/img/base64img.png');
            }
        });});});
    

    【讨论】:

    • 它似乎某些邮件服务器会在敏感区域(例如:图像样式标签),也许是过滤器出错了,真的不应该检查附件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 2021-04-12
    • 2014-04-04
    • 1970-01-01
    相关资源
    最近更新 更多