Skip to content

Commit

Permalink
Reposition try block.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstegelman committed Apr 20, 2013
1 parent e7b982c commit 500bbd5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
version = '1.6.2'
version = '1.6.3'
# The full version, including alpha/beta/rc tags.
release = '1.6.2'
release = '1.6.3'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion mailqueue/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '1.6.2'
VERSION = '1.6.3'
34 changes: 18 additions & 16 deletions mailqueue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from . import defaults


class MailerMessageManager(models.Manager):
def send_queued(self, limit=None):
if limit is None:
Expand All @@ -27,6 +28,7 @@ def send_queued(self, limit=None):
for email in self.filter(sent=False)[:limit]:
email.send()


class MailerMessage(models.Model):
subject = models.CharField(max_length=250, blank=True, null=True)
to_address = models.EmailField(max_length=250)
Expand Down Expand Up @@ -69,23 +71,22 @@ def send(self):
else:
self.last_attempt = datetime.datetime.now()

subject, from_email, to = self.subject, self.from_address, self.to_address
text_content = self.content
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
if self.html_content:
html_content = self.html_content
msg.attach_alternative(html_content, "text/html")
if self.bcc_address:
if ',' in self.bcc_address:
msg.bcc = [ email.strip() for email in self.bcc_address.split(',') ]
else:
msg.bcc = [self.bcc_address, ]

# Add any additional attachments
for attachment in self.attachment_set.all():
msg.attach_file(os.path.join(settings.MEDIA_ROOT, attachment.file_attachment.name))
try:
subject, from_email, to = self.subject, self.from_address, self.to_address
text_content = self.content
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
if self.html_content:
html_content = self.html_content
msg.attach_alternative(html_content, "text/html")
if self.bcc_address:
if ',' in self.bcc_address:
msg.bcc = [ email.strip() for email in self.bcc_address.split(',') ]
else:
msg.bcc = [self.bcc_address, ]

# Add any additional attachments
for attachment in self.attachment_set.all():
msg.attach_file(os.path.join(settings.MEDIA_ROOT, attachment.file_attachment.name))

msg.send()
self.sent = True
except Exception, e:
Expand All @@ -94,6 +95,7 @@ def send(self):

self.save()


class Attachment(models.Model):
file_attachment = models.FileField(upload_to='mail-queue/attachments', blank=True, null=True)
email = models.ForeignKey(MailerMessage, blank=True, null=True)
Expand Down

0 comments on commit 500bbd5

Please sign in to comment.