mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-06 09:57:57 +00:00
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.
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
from django.contrib import admin
|
||||
from django.conf import settings
|
||||
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
from pgweb.core.models import ModerationNotification
|
||||
from util.misc import sendmail
|
||||
from mailqueue.util import send_simple_mail
|
||||
|
||||
|
||||
class PgwebAdmin(admin.ModelAdmin):
|
||||
@ -78,29 +76,20 @@ class PgwebAdmin(admin.ModelAdmin):
|
||||
obj,
|
||||
request.POST['new_notification'])
|
||||
|
||||
msg = MIMEText(msgstr, _charset='utf-8')
|
||||
msg['Subject'] = "postgresql.org moderation notification"
|
||||
msg['To'] = obj.org.email
|
||||
msg['From'] = settings.NOTIFICATION_FROM
|
||||
if hasattr(settings,'SUPPRESS_NOTIFICATIONS') and settings.SUPPRESS_NOTIFICATIONS:
|
||||
print msg.as_string()
|
||||
else:
|
||||
sendmail(msg)
|
||||
send_simple_mail(settings.NOTIFICATION_FROM,
|
||||
obj.org.email,
|
||||
"postgresql.org moderation notification",
|
||||
msgstr)
|
||||
|
||||
# Also generate a mail to the moderators
|
||||
msg = MIMEText(_get_moderator_notification_text(request.POST.has_key('remove_after_notify'),
|
||||
obj,
|
||||
request.POST['new_notification'],
|
||||
request.user.username
|
||||
),
|
||||
_charset='utf-8')
|
||||
msg['Subject'] = "Moderation comment on %s %s" % (obj.__class__._meta.verbose_name, obj.id)
|
||||
msg['To'] = settings.NOTIFICATION_EMAIL
|
||||
msg['From'] = settings.NOTIFICATION_FROM
|
||||
if hasattr(settings,'SUPPRESS_NOTIFICATIONS') and settings.SUPPRESS_NOTIFICATIONS:
|
||||
print msg.as_string()
|
||||
else:
|
||||
sendmail(msg)
|
||||
send_simple_mail(settings.NOTIFICATION_FROM,
|
||||
settings.NOTIFICATION_EMAIL,
|
||||
"Moderation comment on %s %s" % (obj.__class__._meta.verbose_name, obj.id),
|
||||
_get_moderator_notification_text(request.POST.has_key('remove_after_notify'),
|
||||
obj,
|
||||
request.POST['new_notification'],
|
||||
request.user.username
|
||||
))
|
||||
|
||||
if request.POST.has_key('remove_after_notify'):
|
||||
# Object should not be saved, it should be deleted
|
||||
|
Reference in New Issue
Block a user