npm @sendgrid/mail code example
Example 1: sendgrid sdk npm
npm install --save @sendgrid/mail
Example 2: npm sendgrid
npm install --save @sendgrid/mail
Example 3: node js sendgrid
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const fs = require("fs");
pathToAttachment = `${__dirname}/attachment.pdf`;
attachment = fs.readFileSync(pathToAttachment).toString("base64");
const msg = {
to: [email protected]',
from: '[email protected]',
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
};
sgMail.send(msg).catch(err => {
console.log(err);
});