Projet

Général

Profil

« Précédent | Suivant » 

Révision a1790511

Ajouté par Benjamin Dauvergne il y a plus de 10 ans

add a sinkhole email backend

It makes all mails sent by Django go to an unique recipient; use it on
development and preproduction platforms when there are productions
accounts loaded.

Voir les différences:

entrouvert/djommon/email_backends/sinkhole.py
1
from django.conf import settings
2

  
3
from django.core.mail.backends.smtp import EmailBackend as SmtpEmailBackend
4
from django.core.mail.message import sanitize_address
5
from django.utils.encoding import force_bytes
6

  
7
class EmailBackend(SmtpEmailBackend):
8
    def _send(self, email_message):
9
        """A helper method that does the actual sending."""
10
        if not email_message.recipients():
11
            return False
12
        from_email = sanitize_address(email_message.from_email,
13
                email_message.encoding)
14
        recipients = [ settings.EMAIL_SINK_RECIPIENT ]
15
        message = email_message.message()
16
        charset = message.get_charset().get_output_charset() if message.get_charset() else 'utf-8'
17
        try:
18
            self.connection.sendmail(from_email, recipients,
19
                    force_bytes(message.as_string(), charset))
20
        except:
21
            if not self.fail_silently:
22
                raise
23
            return False
24
        return True
25

  

Formats disponibles : Unified diff