python发邮件给多个人发送消息_使用python向多个CC和多个收件人同时发送电子邮件...

单独尝试了多个to和多个cc,这很好,但是当我同时尝试这两种方法时,我得到了一个错误:

文件"path\Continuum\anaconda2\envs\mypython\lib\smtplib.py",

line 870, in sendmail senderrs[each] = (code, resp) TypeError:

unhashable type: '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('''

Hello

'''.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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值