Fix duplicate From headers in e-mails.
Review Request #7588 — Created Aug. 14, 2015 and submitted
A previous change to the mail header code resulted in the From header being included in e-mails twice, with different values. Gmail (and likely other mail systems) check for this, and will error out if they don't match. This was happening because we changed the mail header code to no longer pass any headers down to the EmailMessage constructor, opting instead to inject headers ourselves. This is fine, except we did this to the From header as well, which is considered special. The constructor needs to know about this one, and since we no longer provided it, it fell back to a default address. Our From header then got added later on, resulting in two different headers added. The solution is simple. We just make From special again, and pass its header down to the constructor. I've also renamed a member variable to help guard against any potential future changes to Django's EmailMessage class. Unit tests were added and updated to test for this.
Unit tests passed.
Viewed a copy of the sent e-mail in some manual testing. There was only
one From header, and it had the correct value. Previously, I could see
two conflicting values.
- Change Summary:
-
Left out the most important part of the change (I temporarily regressed to check the unit tests, and didn't git add again.)