Vulcan/server/email.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-08-02 16:11:54 +09:00
buildEmailTemplate = function (htmlContent) {
2014-08-04 10:04:50 +09:00
2014-08-02 16:11:54 +09:00
var juice = Meteor.require('juice');
2014-08-04 10:04:50 +09:00
var emailProperties = {
2014-08-02 16:11:54 +09:00
headerColor: getSetting('headerColor'),
buttonColor: getSetting('buttonColor'),
siteName: getSetting('title'),
2014-08-04 10:04:50 +09:00
tagline: getSetting('tagline'),
2014-08-02 16:11:54 +09:00
siteUrl: getSiteUrl(),
body: htmlContent,
unsubscribe: '',
2014-08-04 09:47:10 +09:00
accountLink: getSiteUrl()+'account',
2014-08-04 10:04:50 +09:00
footer: getSetting('emailFooter'),
logoUrl: getSetting('logoUrl'),
logoHeight: getSetting('logoHeight'),
logoWidth: getSetting('logoWidth')
}
var emailHTML = Handlebars.templates[getTemplate('emailWrapper')](emailProperties);
2014-08-02 16:11:54 +09:00
var inlinedHTML = Async.runSync(function(done) {
juice.juiceContent(emailHTML, {
url: getSiteUrl(),
removeStyleTags: false
}, function (error, result) {
done(null, result);
});
}).result;
2014-08-03 11:50:10 +09:00
var doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
return doctype+inlinedHTML;
}
sendEmail = function(to, subject, html, text){
// TODO: limit who can send emails
// TODO: fix this error: Error: getaddrinfo ENOTFOUND
var from = getSetting('defaultEmail', 'noreply@example.com');
var siteName = getSetting('title');
var subject = '['+siteName+'] '+subject;
if (typeof text == 'undefined'){
// Auto-generate text version if it doesn't exist. Has bugs, but should be good enough.
var htmlToText = Meteor.require('html-to-text');
var text = htmlToText.fromString(html, {
wordwrap: 130
});
}
2014-08-04 19:02:21 +09:00
console.log('//////// sending email…');
console.log('from: '+from);
console.log('to: '+to);
console.log('subject: '+subject);
// console.log('html: '+html);
2014-08-04 19:02:21 +09:00
// console.log('text: '+text);
2014-08-03 11:50:10 +09:00
Email.send({
from: from,
to: to,
subject: subject,
text: text,
html: html
});
};