Monday, October 29, 2018

How to Integrate SendGrid with Node JS

- create an account with Send grid  and follow the below steps

1. Make sure you have the prerequisites
Our library requires Node.js version 0.10, 0.12, or 4.

2. Create an API key
This allows your application to authenticate to our API and send mail. You can enable or disable additional permissions on the

3. Install the package using below command
npm install --save @sendgrid/mail


4. Send your first email
The following is the minimum needed code to send an email:
// using SendGrid's v3 Node.js Library

// https://github.com/sendgrid/sendgrid-nodejs

const sgMail = require('@sendgrid/mail');

sgMail.setApiKey(process.env.SENDGRID_API_KEY);

const msg = {

  to: 'test@example.com',

  from: 'test@example.com',

  subject: 'Sending with SendGrid is Fun',

  text: 'and easy to do anywhere, even with Node.js',

  html: 'and easy to do anywhere, even with Node.js',

};

sgMail.send(msg);

No comments:

Post a Comment