Django

Code

Ticket #9214 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

Allow different `MAIL FROM` or `Return-Path` and `From` headers.

Reported by: mrmachine Assigned to: nobody
Milestone: Component: django.core.mail
Version: SVN Keywords: EmailMessage Return-Path From
Cc: ross@rossp.org Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Currently, EmailMessage.message sets the From header to match the from_email argument in EmailMessage.__init__. This value is also passed as the from_addr argument to smtplib.SMTP.sendmail, which specifies the MAIL FROM or Return-Path header.

This makes it impossible to specify a MAIL FROM or Return-Path header that is different to the From header. This can be a requirement for VERP or other list / bounce management, and also makes it impossible to set a valid From header with multiple identities.

RFC2822 states that the From header specifies the author(s) of the message (those responsible for the writing of the message), who are not necessarily responsible for sending or delivery of the message. The MAIL FROM or Return-Path headers should refer to a single identity, who is responsible for the delivery of the message. This is where bounce messages will go.

I propose that the cleanest solution to this is to change the relevant line from EmailMessage.message to get the From header from self.extra_headers if it exists, and fallback to self.from_email as the default.

This should be entirely backwards compatible, and will allow users to override the From header either for bounce / list management, or to list multiple authors. Currently, if a From header is passed in the headers argument, the resulting message simply contains two From headers, which could yield unexpected results.

This change is important for anyone operating a mailing list, a subscription based email newsletter, or sending any email on behalf of their users or another 3rd party if they want to adhere to anti-SPAM requirements and best practices, e.g. SPF and Sender ID records, catching and removing subscribers who have sent bounce messages, etc.

Attachments

9214-EmailMessage-r9084.diff (1.8 kB) - added by mrmachine on 09/25/08 19:29:20.
Working patch with test.

Change History

09/25/08 19:29:20 changed by mrmachine

  • attachment 9214-EmailMessage-r9084.diff added.

Working patch with test.

09/25/08 19:30:32 changed by mrmachine

  • needs_better_patch changed.
  • has_patch set to 1.
  • version changed from 1.0 to SVN.
  • needs_tests changed.
  • needs_docs changed.

10/29/08 17:22:02 changed by rossp

  • cc set to ross@rossp.org.

02/16/09 14:47:40 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(In [9842]) Fixed #9214: EmailMessage? now respects the From header instead of blindly using from_email. Thanks, Tai Lee.


Add/Change #9214 (Allow different `MAIL FROM` or `Return-Path` and `From` headers.)




Change Properties
Action