mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2024-11-22 02:17:26 +00:00
6d259a6e12
On some machines localhost is defined as something other than 127.0.0.1, and if we mix "127.0.0.1" and "localhost" then some connections won't be to to the address a service is actually running on. This was the case with DKIM: It was running on "localhost" but Postfix was connecting to it at 127.0.0.1. (https://discourse.mailinabox.email/t/opendkim-is-not-running-port-8891/1188/12.) I suppose "localhost" could be an alias to an IPv6 address? We don't really want local services binding on IPv6, so use "127.0.0.1" to be explicit and don't use "localhost" to be sure we get an IPv4 address. Fixes #797
43 lines
952 B
Python
Executable File
43 lines
952 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
# Reads in STDIN. If the stream is not empty, mail it to the system administrator.
|
|
|
|
import sys
|
|
|
|
import smtplib
|
|
from email.message import Message
|
|
|
|
from utils import load_environment
|
|
|
|
# Load system environment info.
|
|
env = load_environment()
|
|
|
|
# Process command line args.
|
|
subject = sys.argv[1]
|
|
|
|
# Administrator's email address.
|
|
admin_addr = "administrator@" + env['PRIMARY_HOSTNAME']
|
|
|
|
# Read in STDIN.
|
|
content = sys.stdin.read().strip()
|
|
|
|
# If there's nothing coming in, just exit.
|
|
if content == "":
|
|
sys.exit(0)
|
|
|
|
# create MIME message
|
|
msg = Message()
|
|
msg['From'] = "\"%s\" <%s>" % (env['PRIMARY_HOSTNAME'], admin_addr)
|
|
msg['To'] = admin_addr
|
|
msg['Subject'] = "[%s] %s" % (env['PRIMARY_HOSTNAME'], subject)
|
|
msg.set_payload(content, "UTF-8")
|
|
|
|
# send
|
|
smtpclient = smtplib.SMTP('127.0.0.1', 25)
|
|
smtpclient.ehlo()
|
|
smtpclient.sendmail(
|
|
admin_addr, # MAIL FROM
|
|
admin_addr, # RCPT TO
|
|
msg.as_string())
|
|
smtpclient.quit()
|