Skip to content

Instantly share code, notes, and snippets.

@davidguttman
Created November 13, 2015 18:28
Show Gist options
  • Save davidguttman/f5652044cb7f65ce3f52 to your computer and use it in GitHub Desktop.
Save davidguttman/f5652044cb7f65ce3f52 to your computer and use it in GitHub Desktop.
Example of a `sendEmail` function that uses Mandrill and powerdrill
var powerdrill = require('powerdrill')('your-api-key-here')
function sendEmail (emailOpts, cb) {
var message = powerdrill()
var to = emailOpts.email
var from = 'Authentic Accounts <email@domain.com>'
var subject, html
if (emailOpts.type === 'signup') {
subject = 'Confirm Your Account'
html = 'Please <a href="' + emailOpts.confirmUrl + '">confirm your account to continue</a>.'
} else if (emailOpts.type === 'change-password-request') {
subject = 'Password Reset'
html = 'If you would like to reset your password <a href="' + emailOpts.changeUrl + '">you may do so here</a>.'
} else {
return cb(new Error('Unknown email type'))
}
message
.to(to)
.from(from)
.subject(subject)
.html(html)
.trackClicks(false)
message.send(cb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment