diff --git a/2.Common_services/1.Postfix/0_setup.py b/2.Common_services/1.Postfix/0_setup.py index 068002b6fca8d8d3d80bb5750df3b82520768faf..bdad62b6e3f736f6aab745616f0fef50075c90eb 100644 --- a/2.Common_services/1.Postfix/0_setup.py +++ b/2.Common_services/1.Postfix/0_setup.py @@ -32,3 +32,23 @@ def setup(interactive=True): 'newaliases', ] utils.run_commands(cmds) + # Setup authentication if any + user = utils.get_conf('EMAIL_SMTP_USER') + if user: + utils.log('Enabling authentication for SMTP relay.') + pwd = utils.get_conf('EMAIL_SMTP_PWD', '') + with open('/etc/postfix/sasl-passwords', 'w') as fo: + fo.write('%s %s:%s\n' % (server, user, pwd)) + auth_conf = ''' +# SMTP relay authentication +smtp_sasl_auth_enable = yes +smtp_sasl_password_maps = hash:/etc/postfix/sasl-passwords +smtp_sasl_security_options = noanonymous +''' + with open('/etc/postfix/main.cf', 'a') as fo: + fo.write(auth_conf) + cmds = [ + 'postmap hash:/etc/postfix/sasl-passwords', + 'service postfix restart', + ] + utils.run_commands(cmds) diff --git a/global-conf.sh b/global-conf.sh index 39dbec6e6fb83ef157ad4ce22a8374bfe1a12f25..06e10d88b623b8a16a5302454e21206b29a2c076 100644 --- a/global-conf.sh +++ b/global-conf.sh @@ -35,6 +35,8 @@ SHELL_ADMIN_PWD= # -- Emails -- EMAIL_SMTP_SERVER= +EMAIL_SMTP_USER= +EMAIL_SMTP_PWD= EMAIL_SENDER='support@ubicast.eu' # separate emails with comas in EMAIL_ADMINS EMAIL_ADMINS='sysadmin@ubicast.eu'