node.js - 对象不是 SendGrid 的函数

标签 node.js azure-mobile-services sendgrid

我正在尝试使用 SendGrid 和 Azure 移动服务发送电子邮件。我在这里使用示例代码供引用:

http://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-nodejs-how-to-send-email/

exports.post = function(request, response) {

    var SendGrid = require('sendgrid');


    var toEmail = 'myemail@mydomain.com';

    var mail = new SendGrid.Email({
        to: toEmail,
        from: toEmail,
        subject: 'Hello SendGrid',
        text: 'This is a sample email message.'
    });

    var sender = new SendGrid('my_user','my_ key');


};

我在创建发件人时遇到类型错误。 Email 对象已按预期创建。我不确定我做错了什么。通过查看 sendgrid.js 中的代码,导出看起来是正确的。有什么想法吗?

这是错误:

脚本“/api/my_api.js”出错。类型错误:对象不是函数

注意: 我已经使用 npm 添加了 sendgrid

来自sendgrid.js

var Sendgrid = function(api_user, api_key, options) {
}

module.exports = Sendgrid;

最佳答案

根据 github 文档:

var sendGrid = require('sendgrid')('my_user', 'my_key');

var mail = new sendGrid.Email({
  to: toEmail,
  from: toEmail,
  subject: 'Hello SendGrid',
  text: 'This is a sample email message.'
});

https://github.com/sendgrid/sendgrid-nodejs

关于node.js - 对象不是 SendGrid 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25495950/

相关文章:

javascript - 控制台错误 NodeJS 配置

iOS 不接收来自 Azure 通知中心的推送

authentication - SendGrid 域身份验证 Heroku

node.js - 下一个 JS : Error: EPERM: operation not permitted, rmdir

node.js - Multer 限制接受的图像

Microsoft Azure 订阅下的 Windows Server 2012 R2 远程桌面许可证激活

python - Sendgrid Python 包中的发件人姓名

php - JSON 常量表示它们在 Ubuntu 上的 PHP 5.5 中未定义

xml - 使用 nodejs 中的 xmlbuilder 在 xml 中添加 namspace

java - Android Studio 连接到 Azure 数据库