首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试使用Sendgrid API连接时出错

尝试使用Sendgrid API连接时出错
EN

Stack Overflow用户
提问于 2020-06-24 03:01:16
回答 1查看 177关注 0票数 0

我正在尝试将Sendgrid api整合到我的nodejs项目中,但它不起作用。

我的代码:

代码语言:javascript
复制
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey('SG.5sNiSHdLTLqFK-jzAiM2WA.gd6wBmu5FzqXVQPe8Ey1yFjKjX1MXnu6sMafSeys');
const msg = {
  to: 'vishal@gmail.com',
  from: 'kartik@gmail.com',
  subject: 'Sending with Twilio SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);
console.log('check   ')

并且我收到以下错误:

代码语言:javascript
复制
(node:12732) UnhandledPromiseRejectionWarning: Error: Forbidden
    at C:\Users\Niranjan\Desktop\krb\web d\node\login-system\node_modules\@sendgrid\client\src\classes\client.js:133:29
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12732) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:12732) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:12732) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at NativeConnection.Connection.openUri (C:\Users\Niranjan\Desktop\krb\web d\node\login-system\node_modules\mongoose\lib\connection.js:826:32)
    at Mongoose.connect (C:\Users\Niranjan\Desktop\krb\web d\node\login-system\node_modules\mongoose\lib\index.js:335:15)
    at Object.<anonymous> (C:\Users\Niranjan\Desktop\krb\web d\node\login-system\src\db\mongoose.js:3:10)
    at Module._compile (internal/modules/cjs/loader.js:1185:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Module.require (internal/modules/cjs/loader.js:1074:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\Niranjan\Desktop\krb\web d\node\login-system\src\app.js:5:1)
    at Module._compile (internal/modules/cjs/loader.js:1185:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
(node:12732) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
EN

回答 1

Stack Overflow用户

发布于 2020-06-24 04:24:33

该错误与Mongo/Mongoose连接有关,与Sendgrid API无关。

请验证以下行:

代码语言:javascript
复制
(node:12732) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at NativeConnection.Connection.openUri (C:\Users\Niranjan\Desktop\krb\web d\node\login-system\node_modules\mongoose\lib\connection.js:826:32)
    at Mongoose.connect (C:\Users\Niranjan\Desktop\krb\web d\node\login-system\node_modules\mongoose\lib\index.js:335:15)
    at Object.<anonymous> (C:\Users\Niranjan\Desktop\krb\web d\node\login-system\src\db\mongoose.js:3:10)

请检查您的Mongo连接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62541957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档