-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
63 lines (53 loc) · 1.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var fs = require('fs'),
path = require('path'),
winston = module.parent.require('winston'),
Meta = module.parent.require('./meta'),
nodemailer = require('nodemailer'),
Emailer = {};
Emailer.init = function(app, middleware, controllers) {
function renderAdminPage(req, res, next) {
res.render('admin/emailers/local', {});
}
app.get('/admin/emailers/local', middleware.admin.buildHeader, renderAdminPage);
app.get('/api/admin/emailers/local', renderAdminPage);
};
Emailer.send = function(data) {
var username = Meta.config['emailer:local:username'];
var pass = Meta.config['emailer:local:password'];
var transportOptions = {
host: Meta.config['emailer:local:host'],
port: Meta.config['emailer:local:port']
};
if( username || pass ) {
transportOptions.auth = {
user: username,
pass: pass
};
}
var transport = nodemailer.createTransport('SMTP', transportOptions);
transport.sendMail({
from: data.from,
to: data.to,
html: data.html,
text: data.plaintext,
subject: data.subject
},function(err,response) {
if ( !err ) {
winston.info('[emailer.smtp] Sent `' + data.template + '` email to uid ' + data.uid);
} else {
winston.warn('[emailer.smtp] Unable to send `' + data.template + '` email to uid ' + data.uid + '!!');
// winston.error('[emailer.smtp] ' + response.message);
}
});
}
Emailer.admin = {
menu: function(custom_header, callback) {
custom_header.plugins.push({
"route": '/emailers/local',
"icon": 'fa-envelope-o',
"name": 'Emailer (Local)'
});
callback(null, custom_header);
}
};
module.exports = Emailer;