-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (60 loc) · 1.87 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
var _email = require("emailjs");
function eMail(options) {
var _self = this;
this.authentication = null; //'PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2'
this.user = null;
this.password = null;
this.host = "localhost";
this.port = null;
this.ssl = false;
this.tls = true;
this.timeout = 5000;
this.domain = null;
this.subject = "Service {$label} is {$status}";
this.text = "Service {$label} status changed to {$status} at {$datetime}";
this.from = "noreply@localhost";
this.to = "root@localhost";
this.attachment = [];
this.logger = console;
this.start = function(info, cb) {
var server = _email.server.connect({
authentication: this.authentication,
user: this.user,
password: this.password,
host: this.host,
port: this.port,
ssl: this.ssl,
tls: this.tls,
timeout: this.timeout,
domain: this.domain
});
var opt = {
text: this.text,
from: this.from,
to: this.to,
subject: this.subject,
attachment: this.attachment
};
info.datetime = (new Date())+'';
for(var i in info) {
if (typeof info[i] !== 'string' && typeof info[i] !== 'number') continue;
opt.text = opt.text.split('{$'+i+'}').join(info[i]);
opt.subject = opt.subject.split('{$'+i+'}').join(info[i]);
opt.from = opt.from.split('{$'+i+'}').join(info[i]);
opt.to = opt.to.split('{$'+i+'}').join(info[i]);
}
for(var i in this) {
if (typeof this[i] !== 'string' && typeof this[i] !== 'number') continue;
opt.text = opt.text.split('{$'+i+'}').join(this[i]);
opt.subject = opt.subject.split('{$'+i+'}').join(this[i]);
opt.from = opt.from.split('{$'+i+'}').join(this[i]);
opt.to = opt.to.split('{$'+i+'}').join(this[i]);
}
server.send(opt, function(err, message) {
if (cb) cb(err, message);
});
};
if (options) for(var i in options) this[i] = options[i];
if (!this.label) this.label = this.name || this.host || 'unbekannt';
}
module.exports = eMail;