summaryrefslogtreecommitdiff
path: root/contrib/qmail-lmtp
blob: c6398f8926402424e4d2a7fbdf52886320b88b86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
#
# Written by Thomas Schneider <qsuscs@qsuscs.de>
# This script is placed in public domain.  If this is not applicable, consider
# it licensed under the CC-0:
# <https://creativecommons.org/publicdomain/zero/1.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)