Skip to content

Instantly share code, notes, and snippets.

@andris9
Last active May 11, 2022 06:25
Show Gist options
  • Save andris9/938a73247b1e76ec515293f580dfa802 to your computer and use it in GitHub Desktop.
Save andris9/938a73247b1e76ec515293f580dfa802 to your computer and use it in GitHub Desktop.
zonemta authentication
# store to config/plugins/authplugin.toml
[authplugin]
enabled="receiver"
// store to plugins/authplugin.js
'use strict';
const username = 'user';
const password = 'secret';
module.exports.title = 'Simple Authentication';
module.exports.init = function(app, done) {
// Listen for AUTH command
app.addHook('smtp:auth', (auth, session, next) => {
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();
};
@deepvoice
Copy link

how would you wire this into the default.js?

"modules/authplugin": {
enabled: true
}
?

Copy link

ghost commented Mar 20, 2018

Still don't working...???

@ndmgrphc
Copy link

Does not seem to work in 2020.

@andris9
Copy link
Author

andris9 commented Dec 14, 2020

For a real production example see the authentication in zonemta-wildduck plugin.

In addition of enabling an authentication plugin you also need to make sure that authentication is even enabled for the smtp interface in ZoneMTA, otherwise the authentication plugin is never called.

@roshanjonah
Copy link

autphlugin.js is a typo - it should be authplugin.js - Unfortunately, I can't seem to get the authentication working. @andris9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment