39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { Transporter, createTransport, TransportOptions } from "nodemailer";
|
|
import { CLUB_NAME, MAIL_HOST, MAIL_PASSWORD, MAIL_PORT, MAIL_SECURE, MAIL_USERNAME } from "../env.defaults";
|
|
|
|
export default class MailHelper {
|
|
private readonly transporter: Transporter;
|
|
|
|
constructor() {
|
|
this.transporter = createTransport({
|
|
host: MAIL_HOST,
|
|
port: MAIL_PORT,
|
|
secure: (MAIL_SECURE as "true" | "false") == "true",
|
|
auth: {
|
|
user: MAIL_USERNAME,
|
|
pass: MAIL_PASSWORD,
|
|
},
|
|
} as TransportOptions);
|
|
}
|
|
|
|
/**
|
|
* @description send mail
|
|
* @param {string} target
|
|
* @param {string} subject
|
|
* @param {string} content
|
|
* @returns {Prmose<*>}
|
|
*/
|
|
async sendMail(target: string, subject: string, content: string): Promise<any> {
|
|
return new Promise((resolve, reject) => {
|
|
this.transporter
|
|
.sendMail({
|
|
from: `"${CLUB_NAME}" <${MAIL_USERNAME}>`,
|
|
to: target,
|
|
subject,
|
|
text: content,
|
|
})
|
|
.then((info) => resolve(info.messageId))
|
|
.catch((e) => reject(e));
|
|
});
|
|
}
|
|
}
|