forked from Danor/nodebb-plugin-emailer-smtp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (58 loc) · 2.09 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
64
65
66
67
68
69
70
71
'use strict';
var winston = module.parent.require('winston'),
Meta = module.parent.require('./meta'),
SendInBlue = require('sendinblue-api'),
Emailer = {};
var settings = {};
Emailer.init = function(data, callback) {
function renderAdminPage(req, res) {
res.render('admin/emailers/local', {});
}
data.router.get('/admin/emailers/local', data.middleware.admin.buildHeader, renderAdminPage);
data.router.get('/api/admin/emailers/local', renderAdminPage);
Meta.settings.get('emailer-local', function(err, _settings) {
if (err) {
return winston.error(err);
}
settings = _settings;
});
callback();
};
Emailer.send = function(data, callback) {
var parameters = {
apiKey: settings['emailer:local:apikey'],
timeout: settings['emailer:local:timeout']
};
var mailOptions = {
from: [data.from, data.from_name],
to: {},
html: data.html,
text: data.plaintext,
subject: data.subject
};
mailOptions.to[data.to] = data.username ? data.username : data.to;
var sendinObj = new SendInBlue(parameters);
sendinObj.send_email(mailOptions, function(err, response){
if ( !err ) {
if (response.code !== 'success') {
winston.info('[emailer.sendinblue] Response: ' + JSON.stringify(response) );
winston.info('[emailer.sendinblue] Mail To: ' + JSON.stringify(mailOptions.to) + ', Mail From: ' + JSON.stringify(mailOptions.from));
}
winston.info('[emailer.sendinblue] Sent `' + data.template + '` email to uid ' + data.uid);
} else {
winston.warn('[emailer.sendinblue] Unable to send `' + data.template + '` email to uid ' + data.uid + '!');
}
callback(err, data);
});
};
Emailer.admin = {
menu: function(custom_header, callback) {
custom_header.plugins.push({
"route": '/emailers/local',
"icon": 'fa-envelope-o',
"name": 'Emailer SendInBlue'
});
callback(null, custom_header);
}
};
module.exports = Emailer;