summaryrefslogtreecommitdiff
path: root/postgresqleu/mailqueue/models.py
diff options
context:
space:
mode:
authorMagnus Hagander2013-04-19 13:56:49 +0000
committerMagnus Hagander2013-04-19 13:58:38 +0000
commitac331360a13f5b87ecc56e7cba4a708d86579ea6 (patch)
tree30fb03faa7b49191c0690e6d76e1bdd517cd884d /postgresqleu/mailqueue/models.py
parenta01fbc87b9f1d010bfee8f370fa64ba66d92e80d (diff)
Add a simple mail queue in the database
Adds a function to call that will render a complete MIME message, and write the resulting text to a database table. Then there is a cron job that runs at regular intervals (every 5 mins or so) and sends all the queued emails. This brings in two important functions: * The ability to "send" emails from regular web views without the risk of ending up blocking on the SMTP server. * The abilitty to "transactionally send email" - meaning that mail sen this way will just disappear if the transaction (normally managed by django) that's open when it was sent ends up rolling back. This prevents re-sending email over and over again when some later step in the process fails.
Diffstat (limited to 'postgresqleu/mailqueue/models.py')
-rw-r--r--postgresqleu/mailqueue/models.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/postgresqleu/mailqueue/models.py b/postgresqleu/mailqueue/models.py
new file mode 100644
index 00000000..f2e7d198
--- /dev/null
+++ b/postgresqleu/mailqueue/models.py
@@ -0,0 +1,11 @@
+from django.db import models
+
+class QueuedMail(models.Model):
+ sender = models.EmailField(max_length=100, null=False, blank=False)
+ receiver = models.EmailField(max_length=100, null=False, blank=False)
+ # We store the raw MIME message, so if there are any attachments or
+ # anything, we just push them right in there!
+ fullmsg = models.TextField(null=False, blank=False)
+
+ def __unicode__(self):
+ return "%s: %s -> %s" % (self.pk, self.sender, self.receiver)