我无法通过图书馆发送电子邮件。 支持将我引导到这里。 我正在尝试从在本地主机上运行的node.js发送。 我首先尝试了npm上列出的示例,但是我收到了401错误,标题为x-no-cors reason
。 因此,我尝试改用@sendgrid/mail
软件包,并因此收到一条错误消息:
TypeError: Cannot read property 'errors' of undefined
at ResponseError.toString (E:\songsplits\api\node_modules\@sendgrid\helpers\classes\response-error.js:45:27)
at Function.CapturedTrace.parseStackAndMessage (E:\songsplits\api\node_modules\bluebird\js\main\captured_trace.js:176:25)
at CapturedTrace.attachExtraTrace (E:\songsplits\api\node_modules\bluebird\js\main\captured_trace.js:79:32)
at Promise._attachExtraTrace (E:\songsplits\api\node_modules\bluebird\js\main\debuggability.js:102:19)
at Promise._rejectCallback (E:\songsplits\api\node_modules\bluebird\js\main\promise.js:471:10)
at E:\songsplits\api\node_modules\bluebird\js\main\promise.js:486:17
at Request.http [as _callback] (E:\songsplits\api\node_modules\@sendgrid\client\src\client.js:124:18)
at Request.self.callback (E:\songsplits\api\node_modules\request\request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (E:\songsplits\api\node_modules\request\request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (E:\songsplits\api\node_modules\request\request.js:1091:12)
at IncomingMessage.g (events.js:291:16)
at emitNone (events.js:91:20)
这是复制的最小模块
email.js
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_KEY);
module.exports.send = function send(html,subject,to,from){
return new Promise((resolve,reject)=>{
sgMail.send({
to,
from,
subject,
html
}).then(resolve).catch(reject);
});
};
index.js
const send = require('./mail');
send(
'<!DOCTYPE html><html><head><title>Hi</title></head><body>Hi</body></html>',
'Hi',
'[email protected]',
'[email protected]',
).then(()=>console.log('sent an email successfully!')).catch(err=>console.log(err));
刚刚也尝试了另一把钥匙,没有布宜诺斯艾利斯。 有时,不会发生错误,然后响应是
Unauthorized (401)
Permission denied, wrong credentials
@thinkingserious您的支持团队是在这里指导我的。
@ r3wt
我知道,如果您将API密钥发布到github,这可能会发生,因为我们的合规团队将禁用您的密钥。
可能发生的另一件事是,如果您打开了IP管理,则只能从特定IP访问您的帐户。 如果您的代码在不在该列表中的IP上运行,也将导致错误。
您能否帮我一个忙,用邮件/发送权限创建一个新的API密钥,然后重试代码?
在执行此操作时,能否请您告诉我们您的支持票号码?
谢谢!!
我现在看到票了...所以我也会去那里看。 谢谢!
@mbernier密钥位于私有
现在,有关我的连接的一些信息:
@伯尼耶
不幸的是, @ mbernier仍然在node.js中发生错误
您的帐户似乎未激活。 您能否登录app.sendgrid.com并在页面顶部查找通知。 它会指导您提供更多有关您自己的信息,以证明您是一个好发件人。
@mbernier,我的客户帐户至少有两年有效。 我检查了日志,客户端正在积极发送其他电子邮件活动和其他东西? 我糊涂了。
在按照交互式帐户菜单中的设置说明进行操作后, @ mbernier起作用了。 好奇怪
抱歉,我不确定会发生什么。 我在支持通知单上做了笔记,因此我希望他们可以通过访问获得更多详细信息。
我很高兴它现在正在工作!
@ r3wt我要结束这个问题,如果您遇到任何其他问题,请告诉我们!
@mbernier问题再次发生。
你好@ r3wt ,
您能通过与他们一起打开的原始支持通知单与我们的支持团队联系,并链接到此主题吗? 我认为您的帐户可能发生了某些情况,并且他们拥有调查您帐户的工具。
谢谢!
最诚挚的问候,
埃尔默
就让我知道,就我所知,我遇到了非常相似的问题(还是新问题)。 解决方案是在应用程序平台heroku https://devcenter.heroku.com/articles/sendgrid#setup -api-key-environment-variable中设置API密钥变量
现在对我来说没有问题。