Allow different `MAIL FROM` or `Return-Path` and `From` headers.
|Reported by:||mrmachine||Owned by:||nobody|
|Severity:||Keywords:||EmailMessage Return-Path From|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.
Change History (4)
Changed 6 years ago by mrmachine
comment:1 Changed 6 years ago by mrmachine
- Has patch set
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Version changed from 1.0 to SVN