Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以python脚本提供多个电子邮件收件人_Python_Email - Fatal编程技术网

以python脚本提供多个电子邮件收件人

以python脚本提供多个电子邮件收件人,python,email,Python,Email,我使用的是python电子邮件程序,当我有1个recepient时可以找到,但当我有2个recepient时失败 有人能帮我解决这个问题吗 代码如下: #Create the container (outer) email message. msg = MIMEMultipart() msg['Subject'] = subject me = "user1@com" recepient = "user1@hotmailcom;user2@hotmail.com" msg['From'] = me

我使用的是python电子邮件程序,当我有1个recepient时可以找到,但当我有2个recepient时失败

有人能帮我解决这个问题吗

代码如下:

#Create the container (outer) email message.
msg = MIMEMultipart()
msg['Subject'] = subject
me = "user1@com"
recepient = "user1@hotmailcom;user2@hotmail.com"
msg['From'] = me
msg['To'] = ''.join(recepient)

用逗号替换分号:

recipient = "user1@hotmailcom;user2@hotmail.com"
msg['To'] = recipient.replace(';', ', ')
显示地址应以逗号分隔:

COMMASPACE = ', '
# family = the list of all recipients' email addresses
msg['To'] = COMMASPACE.join(family)
电子邮件收件人必须以逗号分隔,不能使用分号;这只是微软的惯例:

recepient = "user1@hotmailcom,user2@hotmail.com"
msg['To'] = recepient
当您已经有一个字符串时,不需要使用
str.join()

如果您有一个收件人列表,那么使用
str.join()
将有意义:

recepients = ["user1@hotmailcom", "user2@hotmail.com"]
msg['To'] = ', '.join(recepients)