【问题标题】:Sending images in Mandrill在 Mandrill 中发送图像
【发布时间】:2014-07-26 22:03:38
【问题描述】:

尝试使用 mandrill 通过电子邮件发送 QR 码。到目前为止,这是我所得到的:

db.get(id, function (err, doc) {
  if (err) { fail('Couch', [err, doc]) }
  db.attachment.get(id, 'qr-code.png', function (error, image) {
    // Base64 encode the image.
    var base64 = 'data:image/png;base64,' + new Buffer(image).toString('base64');

到目前为止,我很好。 base64 可以在 html img 标签中使用来呈现二维码,哇哦!接下来是我遇到的问题......

    // Email Tickets to client
    mandrill('/messages/send-template', {
      template_name: 'qr-confirm',
      template_content: [],

如果我只是使用 merge_vars,template_content 应该是空的,对吧?

      message: {
        to: [{email: doc.email, name: doc.name}],
        from_email: 'events@example.com',
        from_name: 'The Team',
        subject: "QR codes attached",
        tags: ['qr'],
        merge_vars: [{
          rcpt: doc.email,
          vars: [
            { name: "name", content: doc.name },
            { name: "attendee", content: doc.id },
            { name: "purchaser", content: doc.purchaser }
          ]
        }],

好的,我需要attachmentsimages 吗,或者如果我使用图片,它会自动附加它们吗?

        attachments: [
          {type: "image/png", name: "qr-code.png", content: base64}
        ],
        images: [
          {type: "image/png", name: "qr-code.png", content: base64}
        ],
      }
    }, function(error, manReply) { console.log(error || manReply) }); // manReply, haha 
  });
});

好吧,尽管如此,我仍然得到一个损坏的附件。有一个附件,它只是坏了 1kb,也没有内联渲染。

任何帮助都会动摇!

【问题讨论】:

    标签: node.js express qr-code mailchimp mandrill


    【解决方案1】:

    好的,问题解决了,只是不要在内容参数中包含data:image/png;base64, :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 2015-07-29
      • 2015-10-22
      • 2021-11-26
      • 2018-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多