问题描述
我有一个主要的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不是构造函数
- 无法兑现诺言吗?
解决方法
我建议删除new
关键字或将其应用于新的静态方法时将其拆分为新行,这会导致错误。
const emailObj = new aaaaa();
emailObj.send(`${userEmail}`);