我正在使用 sendgrid 发送电子邮件。但是当我尝试如下创建电子邮件对象时
let email = new sendgrid.Email();
email.addTo("[email protected] /cdn-cgi/l/email-protection");
email.setFrom("[email protected] /cdn-cgi/l/email-protection");
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 https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html
试试这个 - 它对我有用......
First 安装“sendgrid-web” using:
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: '[email protected] /cdn-cgi/l/email-protection',
from: '[email protected] /cdn-cgi/l/email-protection',
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'});
}
});
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)