mikermcneil / machinepack-mandrill

Node.js machines for use with the Mandrill API
http://node-machine.org/machinepack-mandrill
5 stars 7 forks source link

Send email with multiple attributes #8

Open dottodot opened 9 years ago

dottodot commented 9 years ago

The Mandrill documentation seems to suggest that you can pass an array in merge vars so you can use each but what if you want to pass multiple attributes such as an order and the items ordered. I was hoping you could do something like below and then be able to access the attributes in the Mandrill Template.

Mandrill.sendTemplateEmail({
      templateName: 'Customer Order',
      toEmail: order.shipping_address.email,
      toName: order.shipping_address.first_name + ' ' + order.shipping_address.last_name,
      subject: 'Order ' + order.orderid + ' confirmation',
      mergeVars: [ { name: 'order', content: order }, {name: 'items', content: items}]
})

but this gives an error Error: 1 error validating value so it looks like you can't pass JSON to the the content value.

Do you have any suggestions as to how I can send an array of products ordered to Mandrill?

dottodot commented 9 years ago

OK I found you need to use JSON.stringify and then it will send although still don't seem to be able to access those attributes on Mandrill.

dottodot commented 9 years ago

OK multiple attributes / nested attributes all works fine when I just post json to the Mandrill api however when sending through machinepack-mandrill it doesn't. It's something to do with the formatting of the data sent but can't work out where it's getting messed up.