我正在使用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);
}
});
Run Code Online (Sandbox Code Playgroud)
但它给出了错误
https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html
这应该适合你
var helper = require('sendgrid').mail;
from_email = new helper.Email("test@example.com");
to_email = new helper.Email("test@example.com");
subject = "Sending with SendGrid is Fun";
content = new helper.Content("text/plain", "and easy to do anywhere, even with Node.js");
mail = new helper.Mail(from_email, subject, to_email, content);
var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
var request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: mail.toJSON()
});
sg.API(request, function(error, response) {
console.log(response.statusCode);
console.log(response.body);
console.log(response.headers);
})
Run Code Online (Sandbox Code Playgroud)
来源:https ://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/nodejs.html
| 归档时间: |
|
| 查看次数: |
2062 次 |
| 最近记录: |