-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailServer.js
52 lines (45 loc) · 1.31 KB
/
mailServer.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
'use strict';
// Set configuration
require('./config/config').default('mail');
import { SMTPServer } from 'smtp-server';
import mongoose from './util/mongoose';
import { mailServerOptions } from './config/options'
class MailServer {
constructor() {
this.host = process.env.MAILHOST;
this.port = process.env.MAILPORT;
this.mongooseURI = process.env.MAILMONGOOSEURI;
this.SMTPServer = null;
this.db = mongoose(this.mongooseURI);
this.options = mailServerOptions;
//this.db.createCollection('domains', err => err ? console.error(err) : null);
//this.db.createCollection('keys', err => err ? console.error(err) : null);
}
run() {
this.SMTPServer = new SMTPServer(this.options)
.listen(this.port/*, this.host TODO: see if this is needed */, err => {
if (err) {
return console.error(err);
}
console.log('*****');
console.log('MAIL SERVER');
console.log(`${require('date-and-time').format(new Date(), 'HH:mm:ss | DD MMM Y')}`);
console.log(`${this.host}:${this.port}`);
console.log('*****');
});
}
stop() {
if (this.SMTPServer) {
this.SMTPServer.close(() => this.SMTPServer = null);
}
}
getConfig() {
return {
host: this.host,
port: this.port
};
}
}
export {
MailServer
};