mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +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"
|
||||
|
||||
|
||||
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({
|
||||
host: "localhost",
|
||||
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) => {
|
||||
return await transporter.sendMail({
|
||||
return await (await transporter).sendMail({
|
||||
from: from,
|
||||
to: to,
|
||||
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")
|
||||
|
||||
//TODO: replace handlebars with code
|
||||
@@ -61,4 +57,4 @@ const verificationMail = async (to: string, ) => {
|
||||
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 mjml from "mjml";
|
||||
|
||||
const template_folder = "../../resources/email/templates";
|
||||
const template_folder = "/app/resources/email/templates/";
|
||||
|
||||
const compileTemplates = () => {
|
||||
console.log("Compiling templates: ")
|
||||
|
||||
fs.readdir(template_folder, (err, files) => {
|
||||
if (err) console.log(err);
|
||||
|
||||
files.forEach((file) => {
|
||||
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 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 => {
|
||||
let file = "";
|
||||
file = fs.readFileSync(path.join(template_folder, name, ".hbs")).toString();
|
||||
file = fs.readFileSync(path.join(template_folder, name + ".hbs")).toString();
|
||||
return file;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user