Skip to content
Snippets Groups Projects
Commit df23ae84 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Configure sender address in postfix (refs #22099).

parent 26cb5431
No related branches found
No related tags found
No related merge requests found
......@@ -12,25 +12,41 @@ def setup(interactive=True):
else:
raise Exception('Failed to get hostname.')
# Install and configure postfix
server = utils.get_conf('EMAIL_SMTP_SERVER', '')
if not server:
# with relayless cases emails are not always delivered to google mailing lists unless mailname is ubicast.eu and DNS spf records are set
mailname = 'ubicast.eu'
else:
mailname = utils.get_conf('MS_SERVER_NAME', hostname)
dir_path = utils.get_dir(__file__)
server = utils.get_conf('EMAIL_SMTP_SERVER', '')
cmds = [
'DEBIAN_FRONTEND=noninteractive apt-get install -y postfix mailutils',
'echo "Replacing /etc/postfix/main.cf"',
dict(line='write', template='%s/main.cf' % dir_path, target='/etc/postfix/main.cf', params=(
('{{ hostname }}', hostname),
('{{ smtp }}', server),
)),
]
# Configure mail aliases
if not server:
# with relayless cases emails are not always delivered to google mailing lists unless mailname is ubicast.eu and DNS spf records are set
mailname = 'ubicast.eu'
else:
mailname = utils.get_conf('MS_SERVER_NAME')
if not mailname or mailname == 'mediaserver':
mailname = hostname
cmds.extend([
'echo "%s" > /etc/mailname' % mailname,
'rgrep "root:" /etc/aliases || echo "root: sysadmin@ubicast.eu" >> /etc/aliases',
'service postfix restart',
'newaliases',
]
])
# Configure mail sender
sender = utils.get_conf('EMAIL_SENDER', '')
sender_domain = sender.split('@')[-1]
if sender_domain:
if sender_domain == 'ubicast.eu' and utils.get_conf('MS_SERVER_NAME', '') not in ('', 'mediaserver'):
sender_domain = utils.get_conf('MS_SERVER_NAME')
cmds.extend([
'rm -f /etc/postfix/generic',
'echo "root@localhost %s@%s" >> /etc/postfix/generic' % (hostname, sender_domain),
'echo "root@%s %s@%s" >> /etc/postfix/generic' % (hostname, hostname, sender_domain),
'postmap hash:/etc/postfix/generic',
])
cmds.append('service postfix restart')
utils.run_commands(cmds)
# Setup authentication if any
user = utils.get_conf('EMAIL_SMTP_USER')
......
......@@ -40,3 +40,4 @@ inet_protocols = ipv4
default_transport = smtp
relay_transport = smtp
disable_vrfy_command = yes
smtp_generic_maps = hash:/etc/postfix/generic
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment