如何使用“To”、“CC”和“BCC”发送邮件?

2023-11-26

为了测试目的,我需要在几百个电子邮箱中填充各种消息,我将使用smtplib为了那个原因。我不仅需要将消息发送到特定邮箱,还需要抄送和密件抄送它们。我怎么做?


电子邮件标头对于 SMTP 服务器来说并不重要。只需将抄送和密件抄送收件人添加到to_addrs发送电子邮件时。对于 CC,将它们添加到 CC 标头中。

toaddr = '[email protected]'
cc = ['[email protected]','[email protected]']
bcc = ['[email protected]']
fromaddr = '[email protected]'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %s\r\n" % fromaddr
        + "To: %s\r\n" % toaddr
        + "CC: %s\r\n" % ",".join(cc)
        + "Subject: %s\r\n" % message_subject
        + "\r\n" 
        + message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用“To”、“CC”和“BCC”发送邮件? 的相关文章

随机推荐