forked from zone-eu/zone-mta-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-auth.js
30 lines (24 loc) · 841 Bytes
/
example-auth.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
// store to plugins/authplugin.js
'use strict';
const username = 'user';
const password = 'secret';
module.exports.title = 'Example Authentication';
module.exports.init = function(app, done) {
// Listen for AUTH command
app.addHook('smtp:auth', (auth, session, next) => {
if (!app.config.interfaces.includes(session.interface)) {
// not an interface we care about
next();
}
// validate auth.username and auth.password
if (auth.username !== username || auth.password !== password) {
// authentication failed
let err = new Error('Authentication failed');
err.responseCode = 535;
return next(err);
}
// consider the authentication as succeeded as we did not get an error
next();
});
done();
};