Skip to content

Instantly share code, notes, and snippets.

@ashokfernandez
Last active September 6, 2016 14:53
Show Gist options
  • Save ashokfernandez/37623df7f3c6b70e34b7e0ad5f0212fe to your computer and use it in GitHub Desktop.
Save ashokfernandez/37623df7f3c6b70e34b7e0ad5f0212fe to your computer and use it in GitHub Desktop.
const SENDGRID_API_KEY = 'INSERT API KEY HERE'
const MY_TEMPLATE_ID = 'INSERT TEMPLATE ID HERE'
var sendgrid = require('sendgrid')(process.env.SENDGRID_API_KEY)
// Note the html parameter - you must have this set or you'll get an error about having no
// body set
var email = new sendgrid.Email({
from: 'sentfrom@yourdomain.com',
to: 'my.user@theirdomain.com',
html: '<p></p>',
subject: 'Password reset for Mish Guru'
})
const host = 'https://mydomain.com'
const resetToken = 'sdfdsf-wer234w-csdfrfq3r-sdcs'
email.addSubstitution('%name%', 'John')
email.addSubstitution('%reset_url%', `${host}/reset_password?token=${resetToken}`)
email.addFilter('templates', 'enable', 1)
email.addFilter('templates', 'template_id', MY_TEMPLATE_ID)
sendgrid.send(email, (err, response) => {
if (err) {
console.log(err)
} else {
console.log('Yay! Our templated email has been sent')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment