Try it - it worked for me ...
First install 'sendgrid-web' using:
npm install sendgrid-web
After that, execute the code as follows:
router.get('/email2',function(req,res,next){ var Sendgrid = require("sendgrid-web"); var sendgrid = new Sendgrid({ user: "Your_login_username_for_Sendgrid",//provide the login credentials key:"Your_Api_Key_OR_password" }); sendgrid.send({ to: ' test@gmail.com ', from: ' test@gmail.com ', subject: 'Hello world!', html: '<h1>Hello world!</h1>' }, function (err) { if (err) { console.log(err); res.json({Error:'Error in sending mail'}); } else { console.log("Success."); res.json({Success:'sucessful'}); } }); })
source share