Created
September 4, 2019 02:31
-
-
Save FikriRNurhidayat/c8f7046beacf2c36bda95c76f120a0da to your computer and use it in GitHub Desktop.
Example setup for nodemailer x sendgrid
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
const nodemailer = require('nodemailer'); | |
const sgTransport = require('nodemailer-sendgrid-transport'); | |
const { successResponse, errorsResponse } = require('./responseFormatter.js'); | |
const option = { | |
auth: { | |
api_key: process.env.SENDGRID_API_KEY | |
} | |
} | |
const client = nodemailer.createTransport(sgTransport(option)); | |
module.exports = { | |
sendEmail(mail) { | |
client.sendMail(mail) | |
.then(data => { | |
console.log(successResponse(data)); | |
}) | |
.catch(err => { | |
console.log(errorsResponse(err)); | |
}); | |
}, | |
format(rec, sub, data) { | |
return { | |
from: '[email protected]', | |
to: rec, | |
subject: sub, | |
html: data | |
} | |
}, | |
confirmation(data, link) { | |
return `<h5>Hello ${data.name}<h5>`+`<p>Please do confirm your email address! In publishing and graphic design, lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document without relying on meaningful content. Replacing the actual content with placeholder text allows designers to design the form of the content before the content itself has been produced.<p>`+`<a href="https://api-auth-training.herokuapp.com/api/users/confirm/${link}">Click here to confirm!</a>` | |
}, | |
confirmed() { | |
return "<p>Thanks for your confirmation!</p>" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment