Skip to content

Commit

Permalink
Do not send an email multiple times to the same user if she is in mul…
Browse files Browse the repository at this point in the history
…tiple
  • Loading branch information
arneb committed May 8, 2009
1 parent 5b7d7b9 commit 6175d4e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion campaign/models.py
Expand Up @@ -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


Expand Down

0 comments on commit 6175d4e

Please sign in to comment.