设置抄送人,非常简单,只需要添加一条信息就可以了,例:
cc_list = ['xx@xxx.cn', 'xx@xxx.cn'] msg['Cc'] = ','.join(cc_list)
smtp.sendmail(name, to_list + cc_list, msg.as_string())
完整代码,将账户信息,收发件人信息改成自己的,然后发送邮件,去邮箱查看,就可以发现,现在已经有抄送人了
import smtplib from email.mime.text import MIMEText from email.header import Header name = 'xx@xxx.cn' pwd = 'xxx' to_list = ['xx@xxx.cn'] cc_list = ['xx@xxx.cn', 'xx@xxx.cn'] content = '<html><head><title>test</title></head><body>这是测试邮件内容</body></html>' msg = MIMEText(content, 'html', 'utf-8') msg['form'] = Header('huyang', 'utf-8') msg['to'] = ','.join(to_list) msg['Cc'] = ','.join(cc_list) msg['subject'] = Header('测试邮件', 'utf-8') #---发送 smtp = smtplib.SMTP_SSL('smtp.exmail.qq.com', 465) smtp.login(name, pwd) smtp.sendmail(name, to_list + cc_list, msg.as_string()) print('发送成功!')