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 r.david.murray
Recipients Xavier Bonaventura, r.david.murray
Date 2018-05-24.17:07:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1527181646.7.0.682650639539.issue33633@psf.upfronthosting.co.za>
In-reply-to
Content
smtplib doesn't define any behavior for messages.  I presume you are talking about the email library?

Vis the print behavior, dict-style lookup is defined to return the first matching header.  If you want to see all of them, you can use get_all.  For debugging, you should print the whole message, which would show the duplicate headers:

>>> from email.message import Message
>>> msg = Message()
>>> msg['To'] = 'abc@xyz.com'
>>> msg['To'] = 'xyz@abc.com'
>>> print(msg)
To: abc@xyz.com
To: xyz@abc.com



With the new API this is better, at least in terms of debugging:

>>> from email.message import EmailMessage
>>> msg = EmailMessage()
>>> msg['To'] = 'abc@xyz.com'
>>> print(msg)
To: abc@xyz.com


>>> msg['To'] = 'xyz@abc.com'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rdmurray/python/p38/Lib/email/message.py", line 408, in __setitem__
    "in a message".format(max_count, name))
ValueError: There may be at most 1 To headers in a message


This can't be changed in the old API for backward compatibility reasons.
History
Date User Action Args
2018-05-24 17:07:26r.david.murraysetrecipients: + r.david.murray, Xavier Bonaventura
2018-05-24 17:07:26r.david.murraysetmessageid: <1527181646.7.0.682650639539.issue33633@psf.upfronthosting.co.za>
2018-05-24 17:07:26r.david.murraylinkissue33633 messages
2018-05-24 17:07:26r.david.murraycreate