forked from yoone/API
1
0
Fork 0
API/src/service/mail.service.ts

30 lines
612 B
TypeScript

// src/service/mail.service.ts
import { Provide, Config } from '@midwayjs/core';
import * as nodemailer from 'nodemailer';
@Provide()
export class MailService {
@Config('mailer')
mailConfig;
private transporter;
async init() {
if (!this.transporter) {
this.transporter = nodemailer.createTransport(this.mailConfig);
}
}
async sendMail(to: string, subject: string, text: string) {
await this.init();
const info = await this.transporter.sendMail({
from: `"Canpouches" <${this.mailConfig.auth.user}>`,
to,
subject,
text,
});
return info;
}
}