How to use the email-templates.EmailTemplate function in email-templates

To help you get started, we’ve selected a few email-templates 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 leafingio / monolithic-node-seed / server / modules / Email / controllers.js View on Github external
exports.Signup = (req, res, next) => {
    if(!req.error){
        var templateDir = path.join(__dirname, 'templates', 'signup')
        var signupTemplate = new EmailTemplate(templateDir)
        var infoTemplate = { 
            user: req.user.email,
            name: req.user.username 
        }

        signupTemplate.render(infoTemplate, function(err, result){
            var emailData = {
                to: req.user.email,
                subject: `Welcome ${req.user.username} to Leafing`,
                text: 'Welcome to Leafing',
                html: result.html
            }
            Email(emailData, (err, info) => {
                /* istanbul ignore if */
                if(err) console.log(err)
                // else console.log(`Signup email sent from ${info.envelope.from} to ${info.envelope.to}`)
github tkssharma / e-CommerseHub / e-Commerce-Admin / app / helper / email.ts View on Github external
welcome(user) {
    if (user.email) {
      let templateDir = path.join('app/global/templates', 'emails', 'welcome-email');
      let welcomeEmail = new EmailTemplate(templateDir);
      welcomeEmail.render({ user: user, activate_url: `${url.API}/auth/activate/${user.uuid}` }, (err, result) => {
        transport.sendMail(
          {
            from: emailConfig.global.from,
            to: user.email,
            subject: emailConfig.welcome.subject,
            html: result.html,
          }, (err, info) => {
            // some error occoured...
            console.log(err);
          }
        );
      });
    }
  },
  password_reset(user, password) {
github tkssharma / e-CommerseHub / e-Commerce-Admin / app / helper / email.ts View on Github external
password_reset(user, password) {
    if (user.email) {
      let templateDir = path.join('app/global/templates', 'emails', 'password-reset-email');
      let passwordResetEmail = new EmailTemplate(templateDir);
      passwordResetEmail.render({ user: user, login_url: `${url.FE}/#/auth/login`, password: password }, (err, result) => {
        transport.sendMail(
          {
            from: emailConfig.global.from,
            to: user.email,
            subject: emailConfig.password_reset.subject,
            html: result.html,
          }, (err, info) => {
            // some error occoured...
          }
        );
      });
    }
    if (user.phone_verified) {
      // Twillo.password_reset_notification(user.phone);
    }
github asafkotzer / apartment-finder / email-sender.js View on Github external
const emailConfig = require('./nconf.js').get('email');
const path = require('path')
const sendgrid = require('sendgrid')(emailConfig.sendgridApiKey);

const EmailTemplate = require('email-templates').EmailTemplate
const templateDir = path.join(__dirname, 'new-ad-email')
const emailTemplate = new EmailTemplate(templateDir)

const Handlebars = require('handlebars');
Handlebars.registerHelper('formatSource', function (source) {
  return source === 'agent' ? 'תיווך' : 'פרטי';
});

const helper = require('sendgrid').mail;
const fromEmail = new helper.Email('ads@apartment-finder.com', 'Apartment Finder');
const replyToEmail = new helper.Email(emailConfig.from);
const personalization = new helper.Personalization();
emailConfig.to.forEach(toEmail => {console.log(toEmail); personalization.addTo(new helper.Email(toEmail))});


const send = (options, callback) => {
    let mail = new helper.Mail();
    mail.setReplyTo(replyToEmail);
github lcortess / simple-parse-smtp-adapter / index.js View on Github external
let renderTemplate = (template, data) => {
        let templateDir = template;
        let html = new EmailTemplate(templateDir);

        return new Promise((resolve, reject) => {
            html.render(data, (err, result) => {
                if (err) {
                    console.log(err)
                    reject(err);
                } else {
                    resolve(result);
                }
            });
        });
    };
github waigo / waigo / src / support / mailer / base.js View on Github external
_renderEmailTemplate (templateName, templateVars) {
    this.logger.debug('Rendering template ' + templateName);

    let templatePath = 
      path.dirname( waigo.getPath(`emails/${templateName}/html.pug`) );

    let emailTemplate = new EmailTemplate(templatePath);

    return new Q((resolve, reject) => {
      emailTemplate.render(templateVars, function(err, result) {
        if (err) {
          reject(err);
        } else {
          resolve(result);
        }
      });
    });
  }
github GetStream / Winds / api / models / Users.js View on Github external
sendRegistrationEmail: function(context, callback) {
            let userEmail = this.email
            let EmailTemplate = require('email-templates').EmailTemplate
            let templateDir = path.join(__dirname, '../../views', 'emails', 'signup')
            let newsletter = new EmailTemplate(templateDir)

            newsletter.render(context, function(err, result) {
                MailerService
                    .send({
                        to: userEmail,
                        subject: result.subject,
                        html: result.html,
                        text: result.text
                    })
                    .then(function(result) {
                        callback(null, result)
                    })
                    .catch(callback)
            })

        },
github spamguy / diplomacy / server / mailer / mailer.js View on Github external
function sendOne(templateName, options, cb) {
    if (!options.email)
        return cb(EmailAddressRequiredError);
    var template = new EmailTemplate(path.resolve(templatesDir, templateName));
    template.render(options, function(templateErr, results) {
        if (templateErr)
            return cb(templateErr);

        var apiOptions = {
                auth: {
                    api_key: seekrits.get('mail:auth:password')
                }
            },
            transport = nodemailer.createTransport(sendgridTransport(apiOptions));

        logger.info('Sending mail \'' + templateName + '\' to ' + options.email);
        transport.sendMail({
            from: seekrits.get('mail:defaultFromAddress'),
            to: options.email,
            subject: options.subject,
github Human-Connection / API / server / services / auth-management / notifier.js View on Github external
function buildEmail(templatename, title, linktype, user, additionaloptions) {
    handlebars.registerPartial('header',
      fs.readFileSync(path.join(__dirname, '../../../email-templates', 'layout', 'header.hbs'),'utf8')
    );
    handlebars.registerPartial('footer',
      fs.readFileSync(path.join(__dirname, '../../../email-templates', 'layout', 'footer.hbs'),'utf8')
    );

    const templatePath = path.join(__dirname, '../../../email-templates/account', templatename);

    const hashLink = getLink(linktype, user.verifyToken);
    const baseUrl = getBaseUrl();

    const template = new EmailTemplate(templatePath, {juiceOptions: {
      preserveMediaQueries: true,
      preserveImportant: true,
      removeStyleTags: false
    }});

    const options = {
      templatePath: templatePath,
      title: title,
      name: user.name || user.email,
      link: hashLink,
      returnEmail: returnEmail,
      baseUrl: baseUrl
    };

    Object.assign(options, additionaloptions);
github moleculerjs / moleculer-addons / packages / moleculer-mail / src / index.js View on Github external
getTemplate(templateName) {
			if (this.templates[templateName]) {
				return this.templates[templateName];
			}

			const templatePath = path.join(this.settings.templateFolder, templateName);
			if (fs.existsSync(templatePath)) {
				this.templates[templateName] = new EmailTemplate(templatePath);
				this.Promise.promisifyAll(this.templates[templateName]);

				return this.templates[templateName];
			}
		},

email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for Forward Email and Lad.

MIT
Latest version published 11 months ago

Package Health Score

75 / 100
Full package analysis

Popular email-templates functions