# HG changeset patch # User Brian Neal # Date 1324257669 0 # Node ID dd97341788fa9a21bba43e0c522b11601d24826d # Parent a053fbd3ac986a315a0e842f0f29a1e5bc76a037 For #194, we no longer need the mailer application. diff -r a053fbd3ac98 -r dd97341788fa gpp/mailer/__init__.py --- a/gpp/mailer/__init__.py Mon Dec 19 01:11:43 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -from socket import error as socket_error -import smtplib -import time -import logging - -import django.core.mail - -import mailer.models - - -def enqueue_mail(subject, message, from_email, recipient_list): - """Creates mailer mail queue entries for the given email.""" - - if len(subject) > mailer.models.MAX_SUBJECT: - subject = u'%s...' % subject[:mailer.models.MAX_SUBJECT - 3] - - for recipient in recipient_list: - mailer.models.Message( - from_address=from_email, - to_address=recipient, - subject=subject, - body=message).save() - - -def send_queued_mail(): - """Reads the queued messages from the database, sends them, and removes them - from the queue.""" - - sent, errors = 0, 0 - - logging.debug("Sending queued mail...") - start_time = time.time() - - msgs = mailer.models.Message.objects.all() - for msg in msgs: - try: - django.core.mail.send_mail( - msg.subject, - msg.body, - msg.from_address, - [msg.to_address], - fail_silently=False) - except (socket_error, smtplib.SMTPException), e: - errors += 1 - logging.error("Error sending queued mail: %s", e) - else: - sent += 1 - msg.delete() - - end_time = time.time() - logging.debug("Sent queued mail: %d successful, %d error(s); elapsed time: %.2f" % ( - sent, errors, end_time - start_time)) diff -r a053fbd3ac98 -r dd97341788fa gpp/mailer/admin.py --- a/gpp/mailer/admin.py Mon Dec 19 01:11:43 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -"""This file contains the automatic admin site definitions for the mailer -application.""" -from django.contrib import admin - -from mailer.models import Message - - -class MessageAdmin(admin.ModelAdmin): - list_display = ('from_address', 'to_address', 'subject', 'creation_date') - list_display_links = ('subject', ) - - -admin.site.register(Message, MessageAdmin) diff -r a053fbd3ac98 -r dd97341788fa gpp/mailer/management/commands/send_mail.py --- a/gpp/mailer/management/commands/send_mail.py Mon Dec 19 01:11:43 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -"""send_mail is a custom manage.py command for the mailer application. -It is intended to be called from a cron job periodically to send out queued -email in bulk. This avoids doing the mailing on the HTTP request processing. -""" -from django.core.management.base import NoArgsCommand - -import mailer - - -class Command(NoArgsCommand): - help = "Run periodically to send out queued email." - - def handle_noargs(self, **options): - mailer.send_queued_mail() - diff -r a053fbd3ac98 -r dd97341788fa gpp/mailer/models.py --- a/gpp/mailer/models.py Mon Dec 19 01:11:43 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -"""Models for the mailer application.""" -import datetime - -from django.db import models - - -MAX_SUBJECT = 120 - -class Message(models.Model): - """The model to represent stored emails in the database.""" - from_address = models.EmailField() - to_address = models.EmailField() - subject = models.CharField(max_length=MAX_SUBJECT) - body = models.TextField() - creation_date = models.DateTimeField() - - class Meta: - ordering = ('creation_date', ) - - def __unicode__(self): - return u'From: %s, To: %s, Subj: %s' % ( - self.from_address, self.to_address, self.subject) - - def save(self, *args, **kwargs): - if self.id is None: - self.creation_date = datetime.datetime.now() - super(Message, self).save(*args, **kwargs) diff -r a053fbd3ac98 -r dd97341788fa gpp/settings/base.py --- a/gpp/settings/base.py Mon Dec 19 01:11:43 2011 +0000 +++ b/gpp/settings/base.py Mon Dec 19 01:21:09 2011 +0000 @@ -133,7 +133,6 @@ 'gcalendar', 'irc', 'legacy', - 'mailer', 'membermap', 'messages', 'news',