// 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; } }