Send e-mail to multiple CC and multiple TO recipients simultaneously using python(使用Python同时向多个抄送和多个收件人发送电子邮件)
本文介绍了使用Python同时向多个抄送和多个收件人发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅分别尝试了多个收件人和多个抄送,工作正常,但当我同时尝试这两个时,出现错误:
文件
"pathContinuumanaconda2envsmypythonlibsmtplib.py", 第870行,在Sendmail senderRs[each]=(code,resp)TypeError: 不可散列的类型:‘list’"
编码:
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
strFrom = 'fasdf@dfs.com'
cc='abc.xyz@dfa.com, sdf.xciv@lfk.com'
to='sadf@sdfa.com,123.lfadf@fa.com'
msg = MIMEMultipart('related')
msg['Subject'] = 'Subject'
msg['From'] = strFrom
msg['To'] =to
msg['Cc']=cc
#msg['Bcc']= strBcc
msg.preamble = 'This is a multi-part message in MIME format.'
msgAlternative = MIMEMultipart('alternative')
msg.attach(msgAlternative)
msgText = MIMEText('This is the alternative plain text message.')
msgAlternative.attach(msgText)
msgText = MIMEText('''<html>
<body><p>Hello<p>
</body>
</html> '''.format(**locals()), 'html')
msgAlternative.attach(msgText)
import smtplib
smtp = smtplib.SMTP()
smtp.connect('smtp address')
smtp.ehlo()
smtp.sendmail(strFrom, to, msg.as_string())
smtp.quit()
推荐答案
附件To
或from
应为字符串,并且发送邮件应始终采用列表形式。
cc=['abc.xyz@dfa.com', 'sdf.xciv@lfk.com']
to=['sadf@sdfa.com','123.lfadf@fa.com']
msg['To'] =','.join(to)
msg['Cc']=','.join(cc)
toAddress = to + cc
smtp.sendmail(strFrom, toAddress, msg.as_string())
这篇关于使用Python同时向多个抄送和多个收件人发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:使用Python同时向多个抄送和多个收件人发送电子邮件


基础教程推荐
猜你喜欢
- 合并具有多索引的两个数据帧 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01