tachybase_todo/packages/plugin-notifications/src/models/NotificationService.ts
2021-12-07 19:24:26 +08:00

27 lines
597 B
TypeScript

import { Model } from '@nocobase/database';
import nodemailer from 'nodemailer';
export class NotificationService extends Model {
[key: string]: any;
static createTransport = nodemailer.createTransport;
private _transporter = null;
get transporter() {
if (this._transporter) {
return this._transporter;
}
return this._transporter = NotificationService.createTransport(this.options);
}
async send(options) {
const { from } = this.options;
const mailOptions = {
from,
...options,
};
return this.transporter.sendMail(mailOptions);
}
}