Python电子邮件,如何删除/刷新“收件人”消息中的字段
我正在尝试编写一个 python 程序来将电子邮件发送到多个地址。
每次消息都是相同的,除了收件人的地址之外。 我以为我可以在循环中更改 msg['To'],
for email in emaillist
...
msg['To'] = email
...
...
但实际上每次将 'email' 附加到 msg['To'] 中。
msg.as_string() 就像“收件人:[电子邮件受保护]\nTo :[email protected]'
如何替换 msg['To'] 字段而不是附加字段?
谢谢
I'm trying to write a python rogram to send email to multiple addresses.
Each time the message is the same except for the recipient's address.
I thought i could just change the msg['To'] in the loop,
for email in emaillist
...
msg['To'] = email
...
...
but actually each time 'email' is appended to the msg['To'].
msg.as_string() is like 'To: [email protected]\nTo:[email protected]'
How can I replace the msg['To'] field rather than appending?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要运行
del msg['To']
来清除。 = 运算符是添加而不是替换。有关详细信息,请参阅__setitem__
的文档。You need to run
del msg['To']
to clear. The = operator adds rather than replaces. See the documentation for__setitem__
for details.