diff options
Diffstat (limited to 'pgcommitfest/mailqueue')
-rw-r--r-- | pgcommitfest/mailqueue/models.py | 14 | ||||
-rw-r--r-- | pgcommitfest/mailqueue/util.py | 60 |
2 files changed, 37 insertions, 37 deletions
diff --git a/pgcommitfest/mailqueue/models.py b/pgcommitfest/mailqueue/models.py index f2e7d19..f75ca37 100644 --- a/pgcommitfest/mailqueue/models.py +++ b/pgcommitfest/mailqueue/models.py @@ -1,11 +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) + 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) + def __unicode__(self): + return "%s: %s -> %s" % (self.pk, self.sender, self.receiver) diff --git a/pgcommitfest/mailqueue/util.py b/pgcommitfest/mailqueue/util.py index 9d58750..9abea53 100644 --- a/pgcommitfest/mailqueue/util.py +++ b/pgcommitfest/mailqueue/util.py @@ -9,37 +9,37 @@ from email import encoders from models import QueuedMail def send_simple_mail(sender, receiver, subject, msgtxt, sending_username, attachments=None): - # attachment format, each is a tuple of (name, mimetype,contents) - # content should already be base64 encoded - msg = MIMEMultipart() - msg['Subject'] = subject - msg['To'] = receiver - msg['From'] = sender - msg['Date'] = formatdate(localtime=True) - msg['User-Agent'] = 'pgcommitfest' - if sending_username: - msg['X-cfsender'] = sending_username - - msg.attach(MIMEText(msgtxt, _charset='utf-8')) - - if attachments: - for filename, contenttype, content in attachments: - main,sub = contenttype.split('/') - part = MIMENonMultipart(main,sub) - part.set_payload(content) - part.add_header('Content-Disposition', 'attachment; filename="%s"' % filename) - encoders.encode_base64(part) - msg.attach(part) - - - # Just write it to the queue, so it will be transactionally rolled back - QueuedMail(sender=sender, receiver=receiver, fullmsg=msg.as_string()).save() + # attachment format, each is a tuple of (name, mimetype,contents) + # content should already be base64 encoded + msg = MIMEMultipart() + msg['Subject'] = subject + msg['To'] = receiver + msg['From'] = sender + msg['Date'] = formatdate(localtime=True) + msg['User-Agent'] = 'pgcommitfest' + if sending_username: + msg['X-cfsender'] = sending_username + + msg.attach(MIMEText(msgtxt, _charset='utf-8')) + + if attachments: + for filename, contenttype, content in attachments: + main,sub = contenttype.split('/') + part = MIMENonMultipart(main,sub) + part.set_payload(content) + part.add_header('Content-Disposition', 'attachment; filename="%s"' % filename) + encoders.encode_base64(part) + msg.attach(part) + + + # Just write it to the queue, so it will be transactionally rolled back + QueuedMail(sender=sender, receiver=receiver, fullmsg=msg.as_string()).save() def send_mail(sender, receiver, fullmsg): - # Send an email, prepared as the full MIME encoded mail already - QueuedMail(sender=sender, receiver=receiver, fullmsg=fullmsg).save() + # Send an email, prepared as the full MIME encoded mail already + QueuedMail(sender=sender, receiver=receiver, fullmsg=fullmsg).save() def send_template_mail(sender, senderaccountname, receiver, subject, templatename, templateattr={}, usergenerated=False): - send_simple_mail(sender, receiver, subject, - get_template(templatename).render(templateattr), - senderaccountname) + send_simple_mail(sender, receiver, subject, + get_template(templatename).render(templateattr), + senderaccountname) |