Skip to content

Instantly share code, notes, and snippets.

@aanchirinah
Last active July 28, 2018 08:59
Show Gist options
  • Save aanchirinah/5d6308f5a0a4f8ca4d0a82e6c390e4c0 to your computer and use it in GitHub Desktop.
Save aanchirinah/5d6308f5a0a4f8ca4d0a82e6c390e4c0 to your computer and use it in GitHub Desktop.
require('dotenv').config()
const sendGrid = require('sendgrid').mail;
const sg = require('sendgrid')(process.env.SendGridApiKey);
export const sendVerificationEmail = (to, token) => {
const hostUrl = process.env.hostURL;
const request = sg.emptyRequest({
method: "POST",
path: "/v3/mail/send",
body: {
personalizations: [
{
to: [
{
email: to
}
],
subject:"Verify Your Email"
}
],
from: {
email: "no-reply@example.com"
},
content: [
{
type: 'text/plain',
value: `Click on this link to verify your email ${hostUrl}/verification?token=${token}&email=${to}`
}
]
}
});
return new Promise(function (resolve, reject) {
sg.API(request, function (error, response) {
if (error) {
return reject(error);
}
else {
return resolve(response);
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment