【发布时间】:2020-06-23 19:01:15
【问题描述】:
我正在尝试将 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 连接添加更多详细信息
标签: javascript node.js sendgrid