mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-01-23 12:37:05 +00:00
93d1055869
using "primary" to describe the domain of the box / mail server is confusing when working with multiple domains. Usually the box domain is different from the domain you want to host your mail for.
61 lines
1.4 KiB
Python
Executable File
61 lines
1.4 KiB
Python
Executable File
#!/usr/local/lib/mailinabox/env/bin/python
|
|
|
|
# Reads in STDIN. If the stream is not empty, mail it to the system administrator.
|
|
|
|
import sys
|
|
|
|
import html
|
|
import smtplib
|
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
|
|
# In Python 3.6:
|
|
#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['BOX_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 = MIMEMultipart('alternative')
|
|
|
|
# In Python 3.6:
|
|
#msg = Message()
|
|
|
|
msg['From'] = '"{}" <{}>'.format(env['BOX_HOSTNAME'], admin_addr)
|
|
msg['To'] = admin_addr
|
|
msg['Subject'] = "[{}] {}".format(env['BOX_HOSTNAME'], subject)
|
|
|
|
content_html = f'<html><body><pre style="overflow-x: scroll; white-space: pre;">{html.escape(content)}</pre></body></html>'
|
|
|
|
msg.attach(MIMEText(content, 'plain'))
|
|
msg.attach(MIMEText(content_html, 'html'))
|
|
|
|
# In Python 3.6:
|
|
#msg.set_content(content)
|
|
#msg.add_alternative(content_html, "html")
|
|
|
|
# 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()
|