1down Votefavorite 1 |
here ' s an excerpt from the code I ' m using. I ' m looping through the part of that adds the email; My problem is rather than changing the ' to ' field on each loop and it is appending the ' to ' data. Obviously this causes some issues, since-field ends up getting longer and longer. I tried Msgroot.del_param (' to ') to no avail. I even tried setting the msgroot[' to ') to refer to the first index of a list so I could simply change the value of that Li ST Item (also didn ' t work). From email. Mimemultipart Import mimemultipartmsgroot = Mimemultipart (' related ') msgroot[' to '] = ' [email protected] '
|
you can use the replace_header method.
replace_header (_name, _value)
Replace a header. Replace the first header found in the message this matches _name, retaining header order and field name case. If no matching header was found, a keyerror is raised.
New in version 2.2.2.
For example,
If Msgroot.has_key (' to '): Msgroot.replace_header ("to", someadress) else:msgroot[' to '] = ' [email protected] '
| thank you, that worked perfectly! – dan apr ' at 14:26 |
|
|
|
In Python 3.5 I hadif ‘to‘ in message:Becausehas_keyhas been deprecated.– Tom SitterJune 8 ' + at 21:17 |
|
|
python 3 changed dict syntax. see docs.python.org/3/whatsnew/3.0.html#builtins "removed. Dict.has_key () –use the in operator instead. " – gimel jun 9 ' + at 5:31 |
Original:
Https://stackoverflow.com/questions/5770951/python-how-can-i-change-the-to-field-in-smtp-mime-script-rather-than-adding-a
Modify the From, to fields in the original Python file