我正在关注the documentation为了使用 SendGrid 发送电子邮件:
var sendgrid = require('sendgrid')("username", "passowrd");
var email = new sendgrid.Email({
to: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="66131503142605090b1607081f4805090b" rel="noreferrer noopener nofollow">[email protected]</a>',
from: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89fcfaecfbc9eae6e4f9e8e7f0a7eae6e4" rel="noreferrer noopener nofollow">[email protected]</a>',
subject: 'test mail',
text: 'This is a sample email message.',
html: 'This is a sample <b>HTML<b> email message.'
});
sendgrid.send(email, function(err, json){
if(err) { return console.error(err); }
console.log(json);
});
但我收到错误:
sendgrid.Email is not a constructor
最佳答案
我在各种项目中使用sendgrid,我一直在使用https://github.com/sendgrid/sendgrid-nodejs中的文档。 我想知道 Azure 的文档是否仍然是最新的...
只要您使用@sendgrid/mail
软件包并正确配置您的帐户,就可以。此代码应该有效:
const createSampleMessage = {
to: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56232533241635393b2637382f7835393b" rel="noreferrer noopener nofollow">[email protected]</a>',
from: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5a2f293f281a3935372a3b342374393537" rel="noreferrer noopener nofollow">[email protected]</a>',
subject: 'test mail',
text: 'This is a sample email message.',
html: 'This is a sample <b>HTML<b> email message.'
};
if (process.env.NODE_ENV !== "test") {
await sgMail.send(createSampleMessage);
}
关于javascript - 在 Node.js 中使用 Azure SendGrid 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54128060/