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