mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
- Added Code to get template by name
- Sending mail with compiled template to target
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { writeFile } from "fs";
|
||||
import nodemailer from "nodemailer";
|
||||
import SMTPTransport from "nodemailer/lib/smtp-transport";
|
||||
|
||||
import mjml from "./mjml"
|
||||
|
||||
|
||||
let mailAccount = { user: process.env.MAILUSER + "@mail." + process.env.DOMAIN, pass: process.env.MAILPASSWORD };
|
||||
|
||||
let transporter = nodemailer.createTransport(
|
||||
@@ -47,4 +51,14 @@ const sendMail = async (from: string, to: string, subject: string, text?: string
|
||||
});
|
||||
};
|
||||
|
||||
const verificationMail = async (to: string, ) => {
|
||||
const message = mjml.getTemplate("emailVerification")
|
||||
|
||||
//TODO: replace handlebars with code
|
||||
//TODO: Implement verification codes
|
||||
//TODO: Write endpoints to verify codes
|
||||
|
||||
sendMail(mailAccount.user,to,"Verify Email",undefined,message);
|
||||
}
|
||||
|
||||
export default { sendMail, mailAccount };
|
||||
|
||||
+17
-9
@@ -8,16 +8,24 @@ const compileTemplates = () => {
|
||||
fs.readdir(template_folder, (err, files) => {
|
||||
if (err) console.log(err);
|
||||
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
if (path.extname(file) !== ".mjml") return;
|
||||
|
||||
if(path.extname(file) !== ".mjml") return;
|
||||
|
||||
let content = fs.readFileSync(template_folder + files);
|
||||
let mjmlres = mjml(content.toString());
|
||||
|
||||
let content = fs.readFileSync(template_folder + files)
|
||||
let mjmlres = mjml(content.toString());
|
||||
|
||||
let hbs = template_folder + file.replace(".mjml",".hbs");
|
||||
fs.writeFileSync(hbs,mjmlres.html);
|
||||
})
|
||||
let hbs = template_folder + file.replace(".mjml", ".hbs");
|
||||
fs.writeFileSync(hbs, mjmlres.html);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
compileTemplates(); // This will compile all templates when this file is first included
|
||||
|
||||
const getTemplate = (name: string): string => {
|
||||
let file = "";
|
||||
file = fs.readFileSync(path.join(template_folder, name, ".hbs")).toString();
|
||||
return file;
|
||||
};
|
||||
|
||||
export default { getTemplate };
|
||||
|
||||
Reference in New Issue
Block a user