Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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}`)
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) {
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);
}
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);
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);
}
});
});
};
_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);
}
});
});
}
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)
})
},
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,
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);
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];
}
},