mirror of
https://github.com/detleph/server.git
synced 2026-09-07 16:06:18 +02:00
Fix fix bugs in the mail & mjml library files;
This commit is contained in:
+19
-23
@@ -5,9 +5,23 @@ import SMTPTransport from "nodemailer/lib/smtp-transport";
|
|||||||
import mjml from "./mjml"
|
import mjml from "./mjml"
|
||||||
|
|
||||||
|
|
||||||
let mailAccount = { user: process.env.MAILUSER + "@mail." + process.env.DOMAIN, pass: process.env.MAILPASSWORD };
|
export let mailAccount = { user: process.env.MAILUSER + "@mail." + process.env.DOMAIN, pass: process.env.MAILPASSWORD };
|
||||||
|
|
||||||
let transporter = nodemailer.createTransport(
|
let transporter = (process.env.DEV == "true" || process.env.DOMAIN == undefined) ? (async () => {
|
||||||
|
mailAccount = await nodemailer.createTestAccount();
|
||||||
|
if (process.env.NODE_ENV != "test") {
|
||||||
|
console.log(mailAccount);
|
||||||
|
}
|
||||||
|
return nodemailer.createTransport({
|
||||||
|
host: "smtp.ethereal.email",
|
||||||
|
port: 587,
|
||||||
|
secure: false, // true for 465, false for other ports
|
||||||
|
auth: {
|
||||||
|
user: mailAccount.user, // generated ethereal user
|
||||||
|
pass: mailAccount.pass, // generated ethereal password
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})() : nodemailer.createTransport(
|
||||||
new SMTPTransport({
|
new SMTPTransport({
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 587,
|
port: 587,
|
||||||
@@ -23,26 +37,8 @@ let transporter = nodemailer.createTransport(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (process.env.DEV == "true") {
|
|
||||||
(async () => {
|
|
||||||
mailAccount = await nodemailer.createTestAccount();
|
|
||||||
if (process.env.NODE_ENV != "test") {
|
|
||||||
console.log(mailAccount);
|
|
||||||
}
|
|
||||||
transporter = nodemailer.createTransport({
|
|
||||||
host: "smtp.ethereal.email",
|
|
||||||
port: 587,
|
|
||||||
secure: false, // true for 465, false for other ports
|
|
||||||
auth: {
|
|
||||||
user: mailAccount.user, // generated ethereal user
|
|
||||||
pass: mailAccount.pass, // generated ethereal password
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
|
|
||||||
const sendMail = async (from: string, to: string, subject: string, text?: string, html?: string) => {
|
const sendMail = async (from: string, to: string, subject: string, text?: string, html?: string) => {
|
||||||
return await transporter.sendMail({
|
return await (await transporter).sendMail({
|
||||||
from: from,
|
from: from,
|
||||||
to: to,
|
to: to,
|
||||||
subject: subject,
|
subject: subject,
|
||||||
@@ -51,7 +47,7 @@ const sendMail = async (from: string, to: string, subject: string, text?: string
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const verificationMail = async (to: string, ) => {
|
export const verificationMail = async (to: string, ) => {
|
||||||
const message = mjml.getTemplate("emailVerification")
|
const message = mjml.getTemplate("emailVerification")
|
||||||
|
|
||||||
//TODO: replace handlebars with code
|
//TODO: replace handlebars with code
|
||||||
@@ -61,4 +57,4 @@ const verificationMail = async (to: string, ) => {
|
|||||||
sendMail(mailAccount.user,to,"Verify Email",undefined,message);
|
sendMail(mailAccount.user,to,"Verify Email",undefined,message);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { sendMail, mailAccount };
|
export default { sendMail};
|
||||||
|
|||||||
+5
-3
@@ -2,16 +2,18 @@ import fs from "fs";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import mjml from "mjml";
|
import mjml from "mjml";
|
||||||
|
|
||||||
const template_folder = "../../resources/email/templates";
|
const template_folder = "/app/resources/email/templates/";
|
||||||
|
|
||||||
const compileTemplates = () => {
|
const compileTemplates = () => {
|
||||||
|
console.log("Compiling templates: ")
|
||||||
|
|
||||||
fs.readdir(template_folder, (err, files) => {
|
fs.readdir(template_folder, (err, files) => {
|
||||||
if (err) console.log(err);
|
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 content = fs.readFileSync(template_folder + file);
|
||||||
let mjmlres = mjml(content.toString());
|
let mjmlres = mjml(content.toString());
|
||||||
|
|
||||||
let hbs = template_folder + file.replace(".mjml", ".hbs");
|
let hbs = template_folder + file.replace(".mjml", ".hbs");
|
||||||
@@ -24,7 +26,7 @@ compileTemplates(); // This will compile all templates when this file is first i
|
|||||||
|
|
||||||
const getTemplate = (name: string): string => {
|
const getTemplate = (name: string): string => {
|
||||||
let file = "";
|
let file = "";
|
||||||
file = fs.readFileSync(path.join(template_folder, name, ".hbs")).toString();
|
file = fs.readFileSync(path.join(template_folder, name + ".hbs")).toString();
|
||||||
return file;
|
return file;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user