我正在尝试将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)发布于 2020-06-24 04:24:33
该错误与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连接。
https://stackoverflow.com/questions/62541957
复制相似问题