300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python发邮件给多个人发送消息_使用python向多个CC和多个收件人同时发送电子邮件...

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

时间:2019-09-04 00:06:25

相关推荐

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@'

cc='abc.xyz@, sdf.xciv@'

to='sadf@,123.lfadf@'

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。