This module is a transport plugin for Nodemailer that makes it possible to send through SendGrid's Web API!
npm install nodemailer-transport-sendgrid --save
or using yarn
yarn add nodemailer-transport-sendgrid
const nodemailer = require('nodemailer');
const nmTransportSg = require('nodemailer-transport-sendgrid');
const mailer = nodemailer.createTransport(nmTransportSg('SENDGRID_API_KEY'));
Note: We suggest storing your SendGrid apiKey as enviroment variables.
const email = {
to: '[email protected]',
from: '[email protected]',
subject: 'Email confirmation',
text: 'Visit the link to confirm your email...',
html: '<b>Visit the link to confirm your email...</b>',
category: 'EMAIL_CONFIRMATION', // This parameter is optional, it will make your email into a sendgrid category.
};
mailer.sendMail(email)
.then(console.log)
.catch(console.error);