Merge branch '3.1.0' into 'master'
[mailman.git] / contrib / qmail-lmtp
blobc6398f8926402424e4d2a7fbdf52886320b88b86
1 #!/usr/bin/env python3
3 # Written by Thomas Schneider <qsuscs@qsuscs.de>
4 # This script is placed in public domain.  If this is not applicable, consider
5 # it licensed under the CC-0:
6 # <https://creativecommons.org/publicdomain/zero/1.0/>
8 try:
9     import smtplib
10     import sys
11     import os
13     lmtp = smtplib.LMTP("localhost", int(sys.argv[1]))
15     try:
16         lmtp.sendmail(
17             os.environ['SENDER'],
18             os.environ['EXT' + sys.argv[2]] + "@" + os.environ['HOST'],
19             sys.stdin.buffer.read()
20         )
21     except smtplib.SMTPResponseException as e:
22         if 400 <= e.smtp_code < 500:
23             exit(111)
24         # otherwise, it's either a 5xx aka permanent error or something else
25         # is already b0rked, thus raise -> exit(100) -> have qmail return a
26         # 5xx error
27         else:
28             raise
29 except:
30     exit(100)