查看Python FAQ的源代码
←
Python FAQ
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
你刚才请求的操作只对属于这些用户组的用户开放:
用户
、emailconfirmed
您可以查看并复制此页面的源代码:
===发送MIME邮件附件时,收件人列表注意事项=== #!/usr/bin/env python #coding = utf-8 import smtplib, mimetypes from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.image import MIMEImage msg = MIMEMultipart() msg['From'] = "mail1@163.com" #msg['To'] = ["mail1@163.com","mail1@163.com","mail1@163.com"] 会出错 mail_to = ["mail1@163.com","mail1@163.com","mail1@163.com"] msg['To'] = ', '.join(mail_to) msg['Subject'] = "Report " + (time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) http://bytes.com/topic/python/answers/472868-sending-emails-list-recipients The problem is that SMTP.sendmail and email.MIMEText need two different things. email.MIMEText sets up the “To:” header for the body of the e-mail. It is ONLY used for displaying a result to the human being at the other end, and like all e-mail headers, must be a single string. (Note that it does not actually have to have anything to do with the people who actually receive the message.)SMTP.sendmail, on the other hand, sets up the “envelope” of the message for the SMTP protocol. It needs a Python list of strings, each of which has a single address.So, what you need to do is COMBINE the two replies you received. Set msg‘To’ to a single string, but pass the raw list to sendmail:msg['To'] = ', '.join( emails ) s.sendmail( msg['From'], emails, msg.as_string() )
返回
Python FAQ
。
个人工具
登录/创建账户
名字空间
页面
讨论
变种
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
最近更改
随机页面
工具
链入页面
相关更改
特殊页面