gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 01:03:00 24 4
gpt4 key购买 nike

我正在尝试使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com