npm install chainmailchainmail
=========
chaining api for mandrill in node
Installation
------------
npm install chainmail
Usage
-----
``
var chainmail = require('chainmail')(mandrillApiKey)
chainmail.sendTemplate('welcome-email')
.to('user@server.com')
.withGlobalVars({couponCode: '345ZX'})
.exec(function() { console.log('email sent!') })
`
------------------------------------------
returns a template object
``
var template = chainmail.sendTemplate('welcome-mail')
__Arguments__
* templateName
---------------------------------------
Object that sends a mandrill email template
#### to()
Describes the recipients of the email. Returns the template object.
``
template.to('email@server.com')
template.to(['email@server.com', 'email2@server.com'])
template.to([{e: 'email@server.com'}, {e: 'email2@server.com}], function(r) { return {email: r.e}} })
__Arguments__
* emails
* [mapFn]
--------------------------------------------
#### withGlobalVars()
Sets the template variables that should be populated for every recipient. Returns the template object.
``
template.withGlobalVars({ couponCode: '4563Z' })
__Arguments__
* varMap
--------------------------------------------------
#### withVars()
Sets the template variable that differ for each recipient. Returns the template object.
``
template.withVars(function(e) { return { couponCode: '4563Z' }})
__Arguments__
* varFn
--------------------------------------------------
#### andAttachCsv()
Create a csv attachment. Returns the template object.
``
template.andAttachCsv('attach.csv', new Buffer('file contents'))
__Arguments__
* fileName
* fileContents
--------------------------------------------------
#### exec()
Submits mail request.
```
template.exec(function() {console.log('Woo hoo!')})
__Arguments__
* cb