#!/usr/bin/env python3 # # Written by Thomas Schneider # This script is placed in public domain. If this is not applicable, consider # it licensed under the CC-0: # try: import smtplib import sys import os lmtp = smtplib.LMTP("localhost", int(sys.argv[1])) try: lmtp.sendmail( os.environ['SENDER'], os.environ['EXT' + sys.argv[2]] + "@" + os.environ['HOST'], sys.stdin.buffer.read() ) except smtplib.SMTPResponseException as e: if 400 <= e.smtp_code < 500: exit(111) # otherwise, it's either a 5xx aka permanent error or something else # is already b0rked, thus raise -> exit(100) -> have qmail return a # 5xx error else: raise except: exit(100)