Skip to main content
 首页 » 编程设计

python之如何在回复中添加电子邮件列表

2024年08月15日41落叶

我想发送一个标题为reply-to的邮件我传递了一个列表

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

进入添加标题的方法。这是我的代码。

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

我收到的错误是

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

所以通过错误,我知道我不可能传递电子邮件列表。如何在 header 回复中传递电子邮件列表?还有其他方法可以完成这项工作吗?

请您参考如下方法:

将列表转换为字符串:

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