Permalink
Browse files

Do not send an email multiple times to the same user if she is in mul…

…tiple
  • Loading branch information...
arneb committed May 8, 2009
1 parent 5b7d7b9 commit 6175d4eb6393ba71da31612b6f98cfe35e4a8bdf
Showing with 3 additions and 1 deletion.
  1. +3 −1 campaign/models.py
View
@@ -112,16 +112,18 @@ def _send(self, connection):
html_template = template.Template(self.template.html)
sent = 0
+ used_addresses = []
for recipient_list in self.recipients.all():
for recipient in recipient_list.subscribers.all():
# never send mail to blacklisted email addresses
- if not BlacklistEntry.objects.filter(email=recipient.email).count():
+ if not BlacklistEntry.objects.filter(email=recipient.email).count() and not recipient.email in used_addresses:
msg = EmailMultiAlternatives(subject, connection=connection, to=[recipient.email,])
msg.body = text_template.render(template.Context({'salutation': recipient.salutation,}))
if self.template.html is not None and self.template.html != u"":
html_content = html_template.render(template.Context({'salutation': recipient.salutation,}))
msg.attach_alternative(html_content, 'text/html')
sent += msg.send()
+ used_addresses.append(recipient.email)
return sent

0 comments on commit 6175d4e

Please sign in to comment.