使用Mandrill发送图像 [英] Sending images in Mandrill
本文介绍了使用Mandrill发送图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图通过电子邮件发送二维码。以下是我到目前为止得到的信息:
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: [],
template_content
如果我只使用merge_vars,是否应该为空?
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 }
]
}],
好的,我是否同时需要attachments
和images
,或者如果我使用图像,它会自动附加它们吗?
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,而且也没有内联呈现。
任何帮助都会很棒!!
推荐答案
好了,问题解决了,只是不要在Content参数中包含data:image/png;base64,
:)
这篇关于使用Mandrill发送图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文