I am using sendgrid to send email. but when i try to create the email object as follow
let email = new sendgrid.Email();
email.addTo("[email protected]");
email.setFrom("[email protected]");
email.setSubject("New Unit Added");
email.setHtml("New unit addded </br> Unit Id =" + savedUnit._id);
sendgrid.send(email, function(err, json) {
if (err) {
console.log("Error: " + err);
} else {
console.log(json);
}
});
But it giving error
https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html
Try this - it worked for me...
First install 'sendgrid-web' using:
npm install sendgrid-web
After that, implement the code like this:
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: '[email protected]',
from: '[email protected]',
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'});
}
});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With