我正在尝试使用 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.'
});
关于node.js - 对象不是 SendGrid 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25495950/