summaryrefslogtreecommitdiff
path: root/pgweb/util/misc.py
diff options
context:
space:
mode:
authorMagnus Hagander2014-01-11 11:33:06 +0000
committerMagnus Hagander2014-01-11 11:33:06 +0000
commit8f0b7e6b50f69196747cc3c564c304a3eb9f8c57 (patch)
tree222a930f038360bfdd09654eab496802755d6312 /pgweb/util/misc.py
parentc2b6d459e92db73d3b72379b0bae5d2ab224bfaf (diff)
Switch email sending go through a queue table in the database
Import the code from the PostgreSQL Europe website to handle this, since it's well proven by now. Any points that send email now just write them to the database using the functions in queuedmail.util. This means we can now submit notification emails and such things within transactions and have them properly roll bcak if something goes wrong (so no more incorrect notifications when there is a database error). These emails are picked up by a cronjob that runs frequently (typically once per minute or once every 2 minutes) that submits them to the local mailserver. By doing it out of line, this gives us a much better way of dealing with cases where mail delivery is really slow. The submission from the cronjob is now done with smtp to localhost instead of opening a pipe to the sendmail command - though this should have no major effects on anything. This also removes the setting SUPPRESS_NOTIFICATIONS, as no notifications are actually ever sent unless the cronjob is run. On development systems they will just go into the queuedmail table, and can be deleted from there.
Diffstat (limited to 'pgweb/util/misc.py')
-rw-r--r--pgweb/util/misc.py18
1 files changed, 3 insertions, 15 deletions
diff --git a/pgweb/util/misc.py b/pgweb/util/misc.py
index 656d1f11..a6745902 100644
--- a/pgweb/util/misc.py
+++ b/pgweb/util/misc.py
@@ -1,24 +1,12 @@
-from subprocess import Popen, PIPE
-from email.mime.text import MIMEText
from django.db import connection
from django.conf import settings
+from pgweb.mailqueue.util import send_simple_mail
from pgweb.util.helpers import template_to_string
-def sendmail(msg):
- pipe = Popen("/usr/sbin/sendmail -t", shell=True, stdin=PIPE).stdin
- pipe.write(msg.as_string())
- pipe.close()
-
def send_template_mail(sender, receiver, subject, templatename, templateattr={}):
- msg = MIMEText(
- template_to_string(templatename, templateattr),
- _charset='utf-8')
- msg['Subject'] = subject
- msg['To'] = receiver
- msg['From'] = sender
- sendmail(msg)
-
+ send_simple_mail(sender, receiver, subject,
+ template_to_string(templatename, templateattr))
def is_behind_cache(request):
"""