Last active
September 6, 2016 14:53
-
-
Save ashokfernandez/37623df7f3c6b70e34b7e0ad5f0212fe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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: '[email protected]', | |
to: '[email protected]', | |
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