簡體   English   中英

嘗試與 Sendgrid API 連接時出錯

[英]Error trying to connect with the Sendgrid API

我正在嘗試將 Sendgrid api 合並到我的 nodejs 項目中,但它不起作用。

我的代碼:

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   ')

我收到以下錯誤:

(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)

該錯誤與 Mongo/Mongoose 連接有關,與 Sendgrid API 無關。

請驗證以下幾行:

(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 連接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM