gpt4 book ai didi

email - sendgrid 给出错误 sendgrid.Email 不是构造函数

转载 作者:行者123 更新时间:2023-12-04 15:31:43 26 4
gpt4 key购买 nike

我正在使用 sendgrid 发送电子邮件。但是当我尝试按如下方式创建电子邮件对象时

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);
}
});

但它给出了错误

enter image description here

https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html

最佳答案

试试这个 - 它对我有用......

第一 安装“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'});
}
});
})

关于email - sendgrid 给出错误 sendgrid.Email 不是构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40091170/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com