Teamlinker/code/server/common/mail/mail.ts
sx1989827 ff4db586b3 init
2023-05-27 20:53:32 +08:00

33 lines
860 B
TypeScript

import * as nodemailer from "nodemailer"
import {IServer_Common_Config_Mail} from "../types/config";
let g_mail:Mail
export class Mail {
private transporter:nodemailer.Transporter
private config:IServer_Common_Config_Mail
constructor(config:IServer_Common_Config_Mail) {
g_mail=this;
this.config=config
this.transporter=nodemailer.createTransport({
host:config.host,
port:config.port,
secure:true,
auth:{
user:config.user,
pass:config.pass
}
})
}
async send(to:string,subject:string,content:string) {
await this.transporter.sendMail({
from:this.config.user,
to,
subject,
html:content
})
}
}
export function getMailInstance() {
return g_mail
}