Python:如何使用TO,CC和BCC发送邮件?

Python:如何使用TO,CC和BCC发送邮件?,第1张

Python:如何使用TO,CC和BCC发送邮件?

电子邮件标头与smtp服务器无关。发送电子邮件时,只需将抄送密件抄送收件人添加到toaddrs。对于CC,将它们添加到CC标头中。

toaddr = 'buffy@sunnydale.k12.ca.us'cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']bcc = ['chairman@slayerscouncil.uk']fromaddr = 'giles@sunnydale.k12.ca.us'message_subject = "disturbance in sector 7"message_text = "Three are dead in an attack in the sewers below sector 7."message = "From: %srn" % fromaddr        + "To: %srn" % toaddr        + "CC: %srn" % ",".join(cc)        + "Subject: %srn" % message_subject        + "rn"         + message_texttoaddrs = [toaddr] + cc + bccserver = smtplib.SMTP('smtp.sunnydale.k12.ca.us')server.set_debuglevel(1)server.sendmail(fromaddr, toaddrs, message)server.quit()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5566001.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存