forked from nodemailer/nodemailer-amqp-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (39 loc) · 1.32 KB
/
server.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
'use strict';
const config = require('./config');
const SMTPServer = require('smtp-server').SMTPServer;
// Setup server
const server = new SMTPServer({
// log to console
logger: false,
// not required but nice-to-have
banner: 'Welcome to My Awesome SMTP Server',
// disable STARTTLS to allow authentication in clear text mode
disabledCommands: ['STARTTLS'],
// Accept messages up to 10 MB. This is a soft limit
size: 10 * 1024 * 1024,
// Setup authentication
// Allow all usernames and passwords, no account checking
onAuth(auth, session, callback) {
return callback(null, {
user: {
username: auth.username
}
});
},
// Handle message stream
onData(stream, session, callback) {
console.log('Streaming message from user %s', session.user.username);
console.log('------------------');
stream.pipe(process.stdout);
stream.on('end', () => {
console.log(''); // ensure linebreak after the message
callback(null, 'Message queued as ' + Date.now()); // accept the message once the stream is ended
});
}
});
server.on('error', err => {
console.log('Error occurred');
console.log(err);
});
// start listening
server.listen(config.server.port, config.server.host);