diff --git a/tests/test_email.py b/tests/test_email.py index b1f7f0d03a399dc39c44e4199c831233a99694fb..ffaee75eb98aab2fdae638eaef1b8e3792cf4504 100755 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -46,6 +46,10 @@ def check_listening_port(): print_green('Postfix is listening port 25 correctly.') return True +def check_spf(ip): + status, output = subprocess.getstatusoutput('host -t TXT ubicast.eu') + if ip in output: + return True def check_relay(): print('Checking if SMTP relay conforms to conf.') @@ -57,11 +61,15 @@ def check_relay(): if not configured_relay: # no relay configured, check relayless situations domain = '.'.join(conf.get('MS_SERVER_NAME').split('.')[-2:]) + ip = conf.get('NETWORK_IP') with open('/etc/mailname', 'r') as f: d = f.read() if domain != 'ubicast.tv' and domain not in d: print_red('/etc/mailname does not contain the server domain, emails will probably be treated as spam') return False + if not check_spf(ip): + print_red('ip %s is not in ubicast.eu SPF and emails sent from support@ubicast.eu will be treated as spam' % ip) + return False conf_relay = conf.get('EMAIL_SMTP_SERVER') if conf_relay != configured_relay: print_red('Configured STMP relay (%s) does not match the expected value (%s).' % (configured_relay, conf_relay))