Node.js SendGrid Azure问题

Node.js SendGrid Azure问题,node.js,azure,sendgrid,Node.js,Azure,Sendgrid,我试图在Azure上使用我的Node JS应用程序发送电子邮件,但出现以下错误: TypeError: sendgrid.Email is not a constructor 这是我的密码。我使用了微软的文档 正如@David Tansey提到的,SendGrid团队添加了一个突破性的更改,以支持v3 Web API。是最新版本v5.1.2的工作代码示例 var helper = require('sendgrid').mail; var fromEmail = new helper.Emai

我试图在Azure上使用我的Node JS应用程序发送电子邮件,但出现以下错误:

TypeError: sendgrid.Email is not a constructor
这是我的密码。我使用了微软的文档


正如@David Tansey提到的,SendGrid团队添加了一个突破性的更改,以支持v3 Web API。是最新版本v5.1.2的工作代码示例

var helper = require('sendgrid').mail;
var fromEmail = new helper.Email('test@example.com');
var toEmail = new helper.Email('test@example.com');
var subject = 'Sending with SendGrid is Fun';
var content = new helper.Content('text/plain', 'and easy to do anywhere, even with Node.js');
var mail = new helper.Mail(fromEmail, subject, toEmail, 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) {
  if (error) {
    console.log('Error response received');
  }
  console.log(response.statusCode);
  console.log(response.body);
  console.log(response.headers);
});
但是,如果您希望所提供的代码能够顺利运行,则需要将该版本还原为2.0.0。

请注意:-自您链接的MSDN文章编写以来,SendGrid节点支持部门似乎对其进行了重大更改。我链接的GitHub线程有一个到更新代码示例的链接:
var helper = require('sendgrid').mail;
var fromEmail = new helper.Email('test@example.com');
var toEmail = new helper.Email('test@example.com');
var subject = 'Sending with SendGrid is Fun';
var content = new helper.Content('text/plain', 'and easy to do anywhere, even with Node.js');
var mail = new helper.Mail(fromEmail, subject, toEmail, 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) {
  if (error) {
    console.log('Error response received');
  }
  console.log(response.statusCode);
  console.log(response.body);
  console.log(response.headers);
});