Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
user.save(function(err) {
if (err) return next(err);
// send email
new keystone.Email('reset-password').send({
user: user,
link: '/reset-password/' + user.resetPasswordKey,
subject: 'Reset your password on KeystoneJS Forum',
baseURL: req.protocol + '://' + req.get('host'),
to: user.email,
from: {
name: 'KeystoneJS Forum',
email: 'forum@keystonejs.com'
}
}, next);
});
user.save(function(err) {
if (err) return next(err);
// send email
new keystone.Email('verify-email').send({
user: user,
link: '/auth/verify/?email=' + user.email + '&key=' + user.emailVerificationKey,
subject: 'Please confirm your email address',
baseURL: req.protocol + '://' + req.get('host'),
to: user.email,
from: {
name: 'KeystoneJS Forum',
email: 'forum@keystonejs.com'
}
}, next);
});
var mailgunDomain = process.env.MAILGUN_DOMAIN;
var mandrillApiKey = process.env.MANDRILL_API_KEY;
if (!mandrillApiKey && (!mailgunApiKey || !mailgunDomain)) {
throw Error('You must provide either or both Mailgun or Mandrill auth');
}
var keystone = require('keystone');
keystone.set('emails', './templates');
if (mailgunApiKey) {
keystone.set('email transport', 'mailgun');
keystone.set('mailgun api key', mailgunApiKey);
keystone.set('mailgun domain', mailgunDomain);
new keystone.Email(template).send({}, {
to: to,
from: {
name: 'Keystone Test Project',
email: 'test@keystonejs.com',
},
subject: 'Keystone Test Email!',
}, function (err, result) {
if (err) {
console.error('🤕 Mailgun test failed with error:\n', err);
} else {
console.log('📬 Successfully sent Mailgun test with result:\n', result);
}
});
}
if (mandrillApiKey) {
email: 'test@keystonejs.com',
},
subject: 'Keystone Test Email!',
}, function (err, result) {
if (err) {
console.error('🤕 Mailgun test failed with error:\n', err);
} else {
console.log('📬 Successfully sent Mailgun test with result:\n', result);
}
});
}
if (mandrillApiKey) {
keystone.set('mandrill api key', mandrillApiKey);
new keystone.Email({
templateName: template,
templateExt: 'pug',
transport: 'mandrill',
}).send({}, {
to: [to],
from: {
name: 'Keystone Test Project',
email: 'test@keystonejs.com',
},
subject: 'Keystone Test Email!',
}, function (err, result) {
if (err) {
console.error('🤕 Mandrill test failed with error:\n', err);
} else {
console.log('📬 Successfully sent Mailgun test with result:\n', result);
}
switch (req.params.key) {
case 'forgotten-password':
var email = new keystone.Email('forgotten-password');
email.render({
subject: 'Forgotten Password',
}, renderCallback);
break;
case 'new-reply':
var email = new keystone.Email('new-reply');
loadReply(function() {
email.render({
subject: 'KeystoneJS reply',
reply: data.reply,
topic: { name: 'Testing email notifications on replies' }
}, renderCallback);
});
break;
default:
res.status(404).render('404', { req: req, env: process.env.NODE_ENV });
}
}
.where('state', 'published')
.sort('-createdAt')
.exec(function(err, reply) {
data.reply = reply;
callback();
});
}
switch (req.params.key) {
case 'forgotten-password':
var email = new keystone.Email('forgotten-password');
email.render({
subject: 'Forgotten Password',
}, renderCallback);
break;
case 'new-reply':
var email = new keystone.Email('new-reply');
loadReply(function() {
email.render({
subject: 'KeystoneJS reply',
reply: data.reply,
topic: { name: 'Testing email notifications on replies' }
subscribers.forEach(function(subscriber) {
new keystone.Email('new-topic').send({
subject: 'New topic: ' + topic.name,
topic: topic,
baseURL: req.protocol + '://' + req.get('host'),
to: subscriber.email,
from: {
name: 'KeystoneJS Forum',
email: 'forum@keystonejs.com'
}
}, next);
});
}
topic.watchedBy.forEach(function(watcher) {
new keystone.Email('new-reply').send({
subject: 'Re: ' + topic.name,
topic: topic,
reply: reply,
baseURL: req.protocol + '://' + req.get('host'),
to: watcher.email,
from: {
name: data.author.name.full,
email: 'forum@keystonejs.com'
}
}, next);
});
});