nodemailer 返回的不是构造函数 + 未处理的承诺拒绝
nodemailer is returning is not a constructor + unhandled promise rejection
我有一个主 index.js 并使用
调用 nodemailer
new aaaaa.send(`${userEmail}`)
这是我的 nodemailer.js
const nodemailer = require('nodemailer');
const EmailTemplate = require('email-templates');
const {
nodemailer_client_secret,
nodemailer_refresh_token,
nodemailer_access_token,
nodemailer_user,
nodemailer_client_id,
sp_auth,
} = require('../../config/config');
const { gmail } = require('googleapis/build/src/apis/gmail');
class aaaaa {
// create reusable transporter object using the default SMTP transport
static async send(userEmail, blackListRandom) {
const emailVerify = await nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: nodemailer_user,
clientId: nodemailer_client_id,
clientSecret: nodemailer_client_secret,
refreshToken: nodemailer_refresh_token,
accessToken: nodemailer_access_token,
expires: 3600,
},
});
const email = new EmailTemplate({
transport: emailVerify,
send: true,
preview: false,
});
email
.send({
template: 'hiii',
message: {
from: '',
to: userEmail,
},
locals: {
},
})
.then(() => console.log('email has been sent!'))
}
}
module.exports = aaaaa;
我收到来自这个邮箱的邮件。但是,我怎样才能摆脱我收到的两个警告?
- UnhandlePromiseRejectionWarning: TypeError 不是构造函数
- 处理 promise 拒绝?
我建议删除 new
关键字或将其拆分成一个新行,因为它被应用于导致错误的静态方法。
const emailObj = new aaaaa();
emailObj.send(`${userEmail}`);
我有一个主 index.js 并使用
调用 nodemailer new aaaaa.send(`${userEmail}`)
这是我的 nodemailer.js
const nodemailer = require('nodemailer');
const EmailTemplate = require('email-templates');
const {
nodemailer_client_secret,
nodemailer_refresh_token,
nodemailer_access_token,
nodemailer_user,
nodemailer_client_id,
sp_auth,
} = require('../../config/config');
const { gmail } = require('googleapis/build/src/apis/gmail');
class aaaaa {
// create reusable transporter object using the default SMTP transport
static async send(userEmail, blackListRandom) {
const emailVerify = await nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: nodemailer_user,
clientId: nodemailer_client_id,
clientSecret: nodemailer_client_secret,
refreshToken: nodemailer_refresh_token,
accessToken: nodemailer_access_token,
expires: 3600,
},
});
const email = new EmailTemplate({
transport: emailVerify,
send: true,
preview: false,
});
email
.send({
template: 'hiii',
message: {
from: '',
to: userEmail,
},
locals: {
},
})
.then(() => console.log('email has been sent!'))
}
}
module.exports = aaaaa;
我收到来自这个邮箱的邮件。但是,我怎样才能摆脱我收到的两个警告?
- UnhandlePromiseRejectionWarning: TypeError 不是构造函数
- 处理 promise 拒绝?
我建议删除 new
关键字或将其拆分成一个新行,因为它被应用于导致错误的静态方法。
const emailObj = new aaaaa();
emailObj.send(`${userEmail}`);