SMTPConnection with Return-Path

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.core.mail import SMTPConnection

class CustomSMTPConnection(SMTPConnection):
    """Simple override of SMTPConnection to allow a Return-Path to be specified"""
    def __init__(self, return_path=None, **kwargs):
        self.return_path = return_path
        super(CustomSMTPConnection, self).__init__(**kwargs)
    
    def _send(self, email_message):
        """A helper method that does the actual sending."""
        if not email_message.to:
            return False
        try:
            return_path = self.return_path or email_message.from_email
            self.connection.sendmail(return_path,
                    email_message.recipients(),
                    email_message.message().as_string())
        except:
            if not self.fail_silently:
                raise
            return False
        return True

More like this

  1. Function to create resized versions of an image from a URL and saving it to a local path by obeattie 7 years, 1 month ago
  2. EasyFeed class by limodou 7 years, 1 month ago
  3. Email queue in DB by fish2000 4 years ago
  4. Multiple emails form field by matrix 4 months ago
  5. SSL Middleware by sjzabel 7 years, 1 month ago

Comments

(Forgotten your password?)