diff options
-rw-r--r-- | default_settings.py | 7 | ||||
-rw-r--r-- | utils.py | 19 |
2 files changed, 25 insertions, 1 deletions
diff --git a/default_settings.py b/default_settings.py index 61b0dee..6fc80c3 100644 --- a/default_settings.py +++ b/default_settings.py @@ -1,4 +1,9 @@ -SECRET_KEY = 'remember to change this to something more random and private' +SECRET_KEY = 'remember to change this to something more random and secret' # CHANGE THIS! (e.g. os.urandom(32) ) PASSWORD_ENCRYPTION_KEY = '.\x14\xa7\x1b\xa2:\x1b\xb7\xbck\x1bD w\xab\x87a\xb4\xb7\xca\xf1\x06\xb0\x9f?q\x13\x05\x8dY\xe5<' + +MAIL_DEFAULT_SENDER = 'help-me-help-me-please@spline.de' +MAIL_CONFIRM_SENDER = 'spline accounts <noreply@account.spline.de>' + +SENDMAIL_COMMAND = '/usr/sbin/sendmail' @@ -4,6 +4,7 @@ import ldap import pickle import re from Crypto.Cipher import AES +from email.mime.text import MIMEText from functools import wraps from flask import flash, g, redirect, render_template, request, session, url_for from hashlib import sha1 @@ -117,6 +118,24 @@ def verify_confirmation(realm, token): return pickle.loads(payload) +def send_mail(recipient, subject, body, sender=None): + if sender is None: + sender = current_app.config['MAIL_DEFAULT_SENDER'] + + safe = lambda s: s.split('\n', 1)[0] + + msg = MIMEText(body, _charset='utf-8') + msg['Subject'] = safe(subject) + msg['To'] = safe(recipient) + msg['From'] = safe(sender) + + p = subprocess.Popen([current_app.config['SENDMAIL_COMMAND'], '-t'], + stdin=subprocess.PIPE) + p.stdin.write(msg.as_string()) + p.stdin.close() + + if p.wait() != 0: + raise RuntimeError('sendmail terminated with %d' % p.returncode) # circular import from app import app |