我正在通过nodemailer发送电子邮件,如果没有发送电子邮件,我正在使用sequelize事务回滚上述任务,我在拒绝Promise或抛出错误时遇到了错误。 请帮忙。
//Transaction
await db.sequelize.transaction(async t => {
const facility = await db.Facility.create(body, {transaction: t});
const user = await userCmp.addUser(email.email, t); // add user
await facilityUserCmp.addFacilityUser(facility.id, user.id, t); // add facility_user
emailCmp.verification(user, t); // notify user
if (user) {
res.status(201).send({
success: true,
errors: [],
data: facility
});
}
});
emailCmp.verification(user,t); //这是发送电子邮件的功能。
发送电子邮件代码。
verification: (user, t) => {
try {
const smtpTransport = nodemailer.createTransport({
service: 'SendGrid',
auth: {
user: 'wrong username',
pass: 'wrong password'
}
});
const mailOptions = {
to: 'test email',
from: 'test email',
subject: 'test subject',
text: 'Testing email'
};
smtpTransport.sendMail(mailOptions)
.then((success) => {
console.log(success);
}).catch((e) => {
throw new Error(e);
});
} catch (e) {
console.log("inside catch -p---------------");
}
例外:
(node:10492) UnhandledPromiseRejectionWarning: Error: Invalid login: 535 Authentication failed: Bad username / password
at SMTPConnection._formatError (C:\Users\******\*****\node_modules\nodemailer\lib\smtp-connection\index.js:606:19)
at SMTPConnection._actionAUTHComplete (C:\Users\******\*****\node_modules\nodemailer\lib\smtp-connection\index.js:1335:34)
at SMTPConnection._responseActions.push.str (C:\Users\******\*****\node_modules\nodemailer\lib\smtp-connection\index.js:366:26)
at SMTPConnection._processResponse (C:\Users\******\*****\node_modules\nodemailer\lib\smtp-connection\index.js:762:20)
at SMTPConnection._onData (C:\Users\******\*****\node_modules\nodemailer\lib\smtp-connection\index.js:558:14)
at TLSSocket._socket.on.chunk (C:\Users\******\*****\node_modules\nodemailer\lib\smtp-connection\index.js:709:51)
at TLSSocket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at TLSSocket.Readable.push (_stream_readable.js:219:10)
at TLSWrap.onread (net.js:638:20)
(node:10492) 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)
(node:10492) [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.
请帮帮我。