Vulcan/packages/nova-debug/lib/server/methods.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-06-23 16:42:06 +09:00
import NovaEmail from 'meteor/nova:email';
2016-06-23 15:00:58 +09:00
Meteor.methods({
testEmail: function (emailName) {
2016-06-23 16:42:06 +09:00
const email = NovaEmail.emails[emailName];
2016-06-23 15:00:58 +09:00
if(Users.is.adminById(this.userId)){
console.log("// testing email ["+emailName+"]");
let html, properties;
// if email has a custom way of generating its HTML, use it
if (typeof email.getTestHTML !== "undefined") {
html = email.getTestHTML.bind(email)();
} else {
// else get test object (sample post, comment, user, etc.)
const testObject = email.getTestObject();
// get test object's email properties
properties = email.getProperties(testObject);
// then apply email template to properties, and wrap it with buildTemplate
2016-06-23 16:42:06 +09:00
html = NovaEmail.buildTemplate(NovaEmail.getTemplate(email.template)(properties));
2016-06-23 15:00:58 +09:00
}
// get subject
const subject = "[Test] " + email.subject.bind(email)(properties);
2016-06-23 16:42:06 +09:00
NovaEmail.send (Telescope.settings.get('defaultEmail'), subject, html)
2016-06-23 15:00:58 +09:00
return subject;
} else {
throw new Meteor.Error("must_be_admin", "You must be an admin to send test emails");
}
}
});