ozserver
Version:
API for OZ
44 lines (35 loc) • 996 B
JavaScript
var Mailer, Storage, exports, nodemailer;
nodemailer = require('nodemailer');
Storage = require(global.home + '/script/controllers/storage').Storage;
Mailer = (function() {
function Mailer() {
if (global.mail == null) {
throw 'global.mail is not exists';
}
this.mail = new Storage(global.mail);
this.smtpTransport = nodemailer.createTransport('SMTP', {
host: this.mail.get('host'),
auth: {
user: this.mail.get('user'),
pass: this.mail.get('password')
}
});
}
Mailer.prototype.send = function(email, subject, html) {
if ((email != null) && (subject != null) && (html != null)) {
return this.smtpTransport.sendMail({
from: this.mail.get('email'),
to: email,
subject: subject,
html: html
}, function(err, response) {
if (err) {
throw err;
}
});
}
};
return Mailer;
})();
exports = module.exports = new Mailer();
exports.Mailer = Mailer;