-
-
Save aanchirinah/5d6308f5a0a4f8ca4d0a82e6c390e4c0 to your computer and use it in GitHub Desktop.
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
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