How to use the mjml.mjml2html function in mjml

To help you get started, we’ve selected a few mjml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github justinsisley / mjml-utils / src / builder / index.js View on Github external
builder.build = (filePath, outputDir, extension) => {
  // No-op if filePath is not a file
  if (!fs.statSync(filePath).isFile()) {
    return;
  }

  const filename = getTemplateFilename(filePath).replace('.mjml', extension);

  try {
    const outputPath = path.join(process.cwd(), outputDir);
    mkdir(outputPath);

    const startTime = Date.now();
    const data = fs.readFileSync(`${filePath}`, 'utf8');
    const rendered = mjml2html(data);

    fs.writeFileSync(`${outputPath}/${filename}`, rendered.html);

    const endTime = Date.now();
    const totalTime = endTime - startTime;
    console.log(`Rendered ${filename} in ${totalTime}ms`); // eslint-disable-line
  } catch (error) {
    console.error(`Unable to render ${filename}`);
    console.error(error.message);
  }
};
github contentjet / contentjet-api / dist / viewsets / ProjectInviteViewSet.js View on Github external
const fs = require("fs");
const path = require("path");
const url = require("url");
const ejs = require("ejs");
const { mjml2html } = require('mjml'); // tslint:disable-line
const config_1 = require("../config");
const lodash_1 = require("lodash");
const BaseViewSet_1 = require("./BaseViewSet");
const ProjectInvite_1 = require("../models/ProjectInvite");
const ValidationError_1 = require("../errors/ValidationError");
const middleware_1 = require("../authentication/jwt/middleware");
const middleware_2 = require("../authorization/middleware");
const objection_1 = require("objection");
const validate_1 = require("../utils/validate");
const sendMail = config_1.default.MAIL_BACKEND.sendMail;
const projectInviteHTML = mjml2html(fs.readFileSync(path.resolve(__dirname, '../../templates/mail/project-invite.mjml'), 'utf8')).html;
const projectInviteTXT = fs.readFileSync(path.resolve(__dirname, '../../templates/mail/project-invite.txt'), 'utf8');
const createConstraints = {
    name: {
        presence: true,
        length: {
            maximum: 128
        }
    },
    email: {
        presence: true,
        email: true
    }
};
const acceptConstraints = {
    token: {
        presence: true
github contentjet / contentjet-api / src / viewsets / UserViewSet.ts View on Github external
import url = require('url');
import * as ejs from 'ejs';
import { cloneDeep } from 'lodash';
const { mjml2html } = require('mjml'); // tslint:disable-line
import { transaction } from 'objection';
import User from '../models/User';
import Project from '../models/Project';
import ProjectInvite, { IInvitePayload } from '../models/ProjectInvite';
import BaseViewSet from './BaseViewSet';
import ValidationError from '../errors/ValidationError';
import NotFoundError from '../errors/NotFoundError';
import config from '../config';
import { requireAuthentication } from '../authentication/jwt/middleware';
import validate from '../utils/validate';

const signUpHTML = mjml2html(
  fs.readFileSync(
    path.resolve(__dirname, '../../templates/mail/sign-up-verify.mjml'), 'utf8'
  )
).html;
const signUpTXT = fs.readFileSync(
  path.resolve(__dirname, '../../templates/mail/sign-up-verify.txt'), 'utf8'
);
const requestPasswordResetHTML = mjml2html(
  fs.readFileSync(
    path.resolve(__dirname, '../../templates/mail/request-password-reset.mjml'), 'utf8'
  )
).html;
const requestPasswordResetTXT = fs.readFileSync(
  path.resolve(__dirname, '../../templates/mail/request-password-reset.txt'), 'utf8'
);
github FlowzPlatform / workflow / JobQue / twitter / approval_worker.js View on Github external
.then(function (response) {
        emailTemplateHtml = response.data
        processLog = _.chain(processLog).orderBy(['lastModified'], ['asc']).findLast((f) => { return f.jobId === job.data.jobId }).value()
        for (var i = 0; i < runningProcess.inputProperty[0].entityschema.entity.length; i++) {
          let element = runningProcess.inputProperty[0].entityschema.entity[i].name
            // element = element.toLowerCase()
          let index = emailTemplateHtml.search('"' + element + '"')
            // element = _.capitalize(element)
          emailTemplateHtml = emailTemplateHtml.substr(0, index + element.length + 3) + processLog.input[0][element] + emailTemplateHtml.substr(index + element.length + 3)
        }
        emailTemplateHtml = mjml2html(emailTemplateHtml)
      })
      .catch(function (error) {
github contentjet / contentjet-api / src / viewsets / ProjectInviteViewSet.ts View on Github external
import fs = require('fs');
import path = require('path');
import url = require('url');
import * as ejs from 'ejs';
const { mjml2html } = require('mjml'); // tslint:disable-line
import config from '../config';
import { cloneDeep } from 'lodash';
import BaseViewSet from './BaseViewSet';
import ProjectInvite from '../models/ProjectInvite';
import ValidationError from '../errors/ValidationError';
import { requireAuthentication } from '../authentication/jwt/middleware';
import { requirePermission } from '../authorization/middleware';
import { transaction } from 'objection';
import validate from '../utils/validate';

const projectInviteHTML = mjml2html(
  fs.readFileSync(
    path.resolve(__dirname, '../../templates/mail/project-invite.mjml'), 'utf8'
  )
).html;
const projectInviteTXT = fs.readFileSync(
  path.resolve(__dirname, '../../templates/mail/project-invite.txt'), 'utf8'
);

const createConstraints = {
  name: {
    presence: true,
    length: {
      maximum: 128
    }
  },
  email: {
github SE7ENSKY / webpack-verstat / bin / utils-old.js View on Github external
function handleAdjacentMJML(file, fileSystem, compiler, browserSync, event, mode) {
	const content = customReadFile(file);
	if (content.length) {
		const { error, html } = mjml2html(content);
		if (!error) {
			handleAdjacentHTML(
				file.replace(extname(file), '.html'),
				html,
				false,
				fileSystem,
				compiler,
				browserSync,
				event,
				mode
			);
		} else {
			console.log(error);
		}
	}
}
github justinsisley / mjml-utils / src / sendmail / index.js View on Github external
function resolver(rawTemplate) {
      let { html } = mjml2html(rawTemplate, { filePath: template });

      Object.keys(data).forEach((key) => {
        const regex = new RegExp(`{${key}}`, 'g');
        html = html.replace(regex, data[key]);
      });

      const mailOptions = {
        from: sendmail.config.fromAddress,
        html,
        subject,
        text,
        to,
      };

      sendmail.config.transport.sendMail(mailOptions, (error) => {
        if (error) {
github Mailtrain-org / mailtrain / lib / mailer.js View on Github external
let done = (source, isMjml = false) => {
        if (isMjml) {
            let compiled;
            try {
                compiled = mjml.mjml2html(source);
            } catch (err) {
                return callback(err);
            }
            if (compiled.errors.length) {
                return callback(compiled.errors[0].message || compiled.errors[0]);
            }
            source = compiled.html;
        }
        let renderer = Handlebars.compile(source);
        templates.set(key, renderer);
        callback(null, renderer);
    };
github mikelambert / dancedeets-monorepo / server / node_server / renderServer.js View on Github external
app.post('/mjml-render', (req, res) => {
  const mjmlData = req.body.mjml;
  const html = mjml2html(mjmlData);
  res.json({
    error: null,
    html,
  });
});
server.listen(PORT, ADDRESS, () => {

mjml

MJML: the only framework that makes responsive-email easy

MIT
Latest version published 11 months ago

Package Health Score

85 / 100
Full package analysis