2014-06-05 55 views
2

試圖通過電子郵件發送QR碼與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標記以呈現qr碼,嗚呼!

// 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: '[email protected]', 
     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,而不是內聯渲染。

任何幫助將搖滾!

回答

4

好的,問題解決了,只是在內容參數中不包括data:image/png;base64,:)