space-accessstablestagetest-hooks
Last change
on this file was
d80f2ad,
checked in by Alex Dehnert <adehnert@…>, 14 years ago
|
Email backend that forces all mail to one address
|
-
Property mode set to
100644
|
File size:
895 bytes
|
Rev | Line | |
---|
[d80f2ad] | 1 | from django.conf import settings |
---|
| 2 | from django.core.mail.backends import smtp |
---|
| 3 | from django.core.mail.message import sanitize_address |
---|
| 4 | |
---|
| 5 | class ForcedRecipientEmailBackend(smtp.EmailBackend): |
---|
| 6 | def _send(self, email_message): |
---|
| 7 | """A helper method that does the actual sending.""" |
---|
| 8 | if not email_message.recipients(): |
---|
| 9 | return False |
---|
| 10 | if settings.EMAIL_FORCED_RECIPIENTS_LABEL not in email_message.to: |
---|
| 11 | email_message.to.append(settings.EMAIL_FORCED_RECIPIENTS_LABEL) |
---|
| 12 | from_email = sanitize_address(email_message.from_email, email_message.encoding) |
---|
| 13 | recipients = settings.EMAIL_FORCED_RECIPIENTS |
---|
| 14 | try: |
---|
| 15 | self.connection.sendmail(from_email, recipients, |
---|
| 16 | email_message.message().as_string()) |
---|
| 17 | except: |
---|
| 18 | if not self.fail_silently: |
---|
| 19 | raise |
---|
| 20 | return False |
---|
| 21 | return True |
---|
Note: See
TracBrowser
for help on using the repository browser.