chainmail
v0.0.3
Published
chained API for mandrill
Downloads
2
Readme
chainmail
chaining api for mandrill in node
Installation
npm install chainmail
Usage
Initialization and quick example
var chainmail = require('chainmail')(mandrillApiKey)
chainmail.sendTemplate('welcome-email')
.to('[email protected]')
.withGlobalVars({couponCode: '345ZX'})
.exec(function() { console.log('email sent!') })
sendTemplate()
returns a template object
var template = chainmail.sendTemplate('welcome-mail')
Arguments
- templateName - the name of the template you're sending
Template
Object that sends a mandrill email template
to()
Describes the recipients of the email. Returns the template object.
template.to('[email protected]')
template.to(['[email protected]', '[email protected]'])
template.to([{e: '[email protected]'}, {e: '[email protected]}], function(r) { return {email: r.e}} })
Arguments
- emails - the email, array of emails or array of objects to send the email to
- [mapFn] - if providing an array of objects, the function that maps the object to email info
withGlobalVars()
Sets the template variables that should be populated for every recipient. Returns the template object.
template.withGlobalVars({ couponCode: '4563Z' })
Arguments
- varMap - object where the keys signify var names and the value signify var values
withVars()
Sets the template variable that differ for each recipient. Returns the template object.
template.withVars(function(e) { return { couponCode: '4563Z' }})
Arguments
- varFn - Function that accepts the email object set in to and creates a varMap
andAttachCsv()
Create a csv attachment. Returns the template object.
template.andAttachCsv('attach.csv', new Buffer('file contents'))
Arguments
- fileName - Name of attachment
- fileContents - Buffer of attachment contents
exec()
Submits mail request.
template.exec(function() {console.log('Woo hoo!')})
Arguments
- cb - Callback function. Takes an err and response argument.