This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Xavier Bonaventura
Recipients Xavier Bonaventura
Date 2018-05-24.10:50:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1527159033.13.0.682650639539.issue33633@psf.upfronthosting.co.za>
In-reply-to
Content
The behavior when you assign an email to 'To' is counter intuitive.
When you do:

msg['To'] = 'foo@mail.com'

this appends the email instead of really assigning it.
This is because the assignment operator is overwritten.

Imagine that you have code like this:

msg = MIMEText("The report at *link* has been updated")
for recipient in recipient_list:
    msg['To'] = recipient_email
    server.sendmail(from_address, recipient_email, msg.as_string())

This will send the email to the first person N times, to the second N-1, etc.

In case that you want to debug, it is also a problem. In case that the append is the expected behaviour, one would expect that at least if you do a print like this you see the full list.

print(msg['To'])

Instead of that, in this example of code:
msg['To'] = 'foo@mail.com'
msg['To'] = 'foo@mail.com'
print(msg['To'])

It will print:
foo@mail.com

But the message will be sent two times.
History
Date User Action Args
2018-05-24 10:50:33Xavier Bonaventurasetrecipients: + Xavier Bonaventura
2018-05-24 10:50:33Xavier Bonaventurasetmessageid: <1527159033.13.0.682650639539.issue33633@psf.upfronthosting.co.za>
2018-05-24 10:50:33Xavier Bonaventuralinkissue33633 messages
2018-05-24 10:50:33Xavier Bonaventuracreate