【发布时间】:2019-05-20 02:10:06
【问题描述】:
我想从我的应用程序 (Angular) 发送电子邮件。 我尝试在我的后面使用 @sendgrid/mail 和 node.js,但它不起作用。
错误是:
(node:18224) UnhandledPromiseRejectionWarning: Error: Unauthorized
at Request.http [as _callback] (C:\Users\Gauthier\tla\back\node_modules\@sendgrid\client\src\classes\client.js:124:25)
at Request.self.callback (C:\Users\Gauthier\tla\back\node_modules\request\request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (C:\Users\Gauthier\tla\back\node_modules\request\request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (C:\Users\Gauthier\tla\back\node_modules\request\request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
(node:18224) 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(). (rejection id: 1)
(node:18224) [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:18224) UnhandledPromiseRejectionWarning: Error: Unauthorized
at Request.http [as _callback] (C:\Users\Gauthier\tla\back\node_modules\@sendgrid\client\src\classes\client.js:124:25)
at Request.self.callback (C:\Users\Gauthier\tla\back\node_modules\request\request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (C:\Users\Gauthier\tla\back\node_modules\request\request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (C:\Users\Gauthier\tla\back\node_modules\request\request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
(node:18224) 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(). (rejection id: 2)
也许有人可以帮助我?
请在下面找到我的 app.js
var sendgrid = require('@sendgrid/mail');
app.post('/sendemail', (request, response) => {
const body = request.body;
const email = body.email;
console.log('sendMail');
SENDGRID_APY_KEY = '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';
sendgrid.setApiKey(process.env.SENDGRID_APY_KEY);
const msg = {
to: 'ambre.naude@infogene.fr',
from: 'infogene69@gmail.com',
subject: 'Votre mot de passe provisoire',
text: 'Bonjour !',
html: '<p>Bonjour!</p><p>Voici votre mot de passe provisoire:</p> <p>Cordialement,</p> <p>Infogène Lyon</p>',
};
sendgrid.send(msg);
console.log(msg);
});
【问题讨论】:
标签: node.js angular http email sendgrid