1

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: abc@gmail.com\nTo:xyz@gmail.com'

How can I replace the msg['To'] field rather than appending?

Thank you

vincent_zhang
  • 93
  • 1
  • 6

1 Answers1

1

You need to run del msg['To'] to clear. The = operator adds rather than replaces. See the documentation for __setitem__ for details.

ABS
  • 2,092
  • 1
  • 13
  • 6