def send_messages(self, email_messages): for message in email_messages: send = True if self.filter: all_recipients = message.to + message.cc + message.bcc for address in all_recipients: if address not in self.pass_emails: send = False status = '' message_string = '%s (to:%s cc:%s bcc:%s)' % ( message.subject, list2comma_separated(message.to), list2comma_separated(message.cc), list2comma_separated(message.bcc), ) if send: status = 'SENDING E-MAIL - ' + message_string else: status = 'FILTERING E-MAIL - ' + message_string if self.redirect_to: message.subject = 'REDIRECTED - ' + message_string message.to = self.redirect_to message.cc = [] message.bcc = [] send = True status += ' - redirecting to %s' % list2comma_separated(self.redirect_to) else: status += ' - not redirecting' logger.info(status) if send: super(FilteringEmailBackend, self).send_messages(email_messages)
def django_message_to_db_email(message): connection = message.connection message.connection = None dump = json.dumps(message.__dict__) message.connection = connection email = EmailMessage() email.from_email = message.from_email email.subject = message.subject email.body = message.body email.to = list2comma_separated(message.to) email.cc = list2comma_separated(message.cc) email.bcc = list2comma_separated(message.bcc) email.email_class = get_full_class(message) email.email_dump = dump return email