Created
November 13, 2015 18:28
-
-
Save davidguttman/f5652044cb7f65ce3f52 to your computer and use it in GitHub Desktop.
Example of a `sendEmail` function that uses Mandrill and powerdrill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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