Search code examples
pythonemailsmtpsmtplib

How to add List of emails in the reply to


I want to send a mail with the header reply-to I passed a list

replyto=['email1@gmal.com','email2@gmail.com']

into the add header method. here is my code.

message = MIMEMultipart("alternative")
message['to'] = ",".join(to)
message['from'] = sender
message['subject'] = subject
message.add_header('In-Reply-To', replyto)

The error I received is

TypeError: sequence item 0: expected str instance, list found

So by the error, I get to know that there's no possibility that I can pass a list of emails. How to pass a list of emails in the header reply-to? Are there any other ways to get the job done?


Solution

  • Convert List to string:

    str1 = ','.join(replyto)
    message.add_header('In-Reply-To', str1)