sendgrid给出错误sendgrid.Email不是构造函数 [英] sendgrid giving error sendgrid.Email is not a constructor
本文介绍了sendgrid给出错误sendgrid.Email不是构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用sendgrid发送电子邮件。但是当我尝试按照以下方式创建电子邮件对象时
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("rhushikeshl@test.com");
email.setFrom("customercare@test.com");
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);
}
});
但是它给出了错误
https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html
推荐答案
尝试一下-对我有用...
Try this - it worked for me...
首先使用以下命令安装'sendgrid-web':
npm install sendgrid-web
之后,实现如下代码:
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'});
}
});
})
这篇关于sendgrid给出错误sendgrid.Email不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文