Made it so, when using the batch code generator, it sends e-mails to everyone
This commit is contained in:
42
src/email/index.ts
Normal file
42
src/email/index.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import nodemailer from "nodemailer";
|
||||
import hbs from "nodemailer-express-handlebars";
|
||||
import path from "path";
|
||||
|
||||
interface MailOptions {
|
||||
from: string;
|
||||
to: string[];
|
||||
subject: string;
|
||||
template: string;
|
||||
context: object;
|
||||
}
|
||||
|
||||
export function prepareMailer(): nodemailer.Transporter {
|
||||
const transport = nodemailer.createTransport({
|
||||
host: process.env.SMTP_HOST,
|
||||
auth: {
|
||||
user: process.env.MAIL_USER!,
|
||||
pass: process.env.MAIL_PASS!,
|
||||
},
|
||||
});
|
||||
|
||||
const handlebarOptions: hbs.NodemailerExpressHandlebarsOptions = {
|
||||
viewEngine: {
|
||||
partialsDir: path.resolve("src/email/templates"),
|
||||
defaultLayout: "src/email/templates/main",
|
||||
},
|
||||
viewPath: path.resolve("src/email/templates"),
|
||||
};
|
||||
|
||||
transport.use("compile", hbs(handlebarOptions));
|
||||
return transport;
|
||||
}
|
||||
|
||||
export function prepareMailOptions(context: object, to: string[], subject: string, template: string): MailOptions {
|
||||
return {
|
||||
from: process.env.MAIL_USER!,
|
||||
to,
|
||||
subject,
|
||||
template,
|
||||
context,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user