A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

python 实现SMTP发送邮件(三)-抄送人

主要添加msg["cc"]="234567@qq.com"即可

[Python] 纯文本查看 复制代码
import smtplib
  from email.mime.text import MIMEText
  from email.header import Header

  # 配置邮箱服务器
  smtpserver = "smtp.163.com"

  # 用户/密码
  user = "admin@163.com"
  password = "123456"

  # 发送者邮箱
  sender = "admin@163.com"

  # 接收者邮箱
  receiver = ["123456@163.com","234567@qq.com"]

  # 邮件主题
  subject = "Python-email2"

  msg = MIMEText('<html><h1>你好!</h1></html>', "html", "utf-8")
  msg["Subject"] = Header(subject, "utf-8")


  #多人接收邮件,一个接收方,一个是抄送
  msg['From'] = "admin@163.com"
  msg['To'] = "123456@163.com"
  msg["cc"]="234567@qq.com"

  if __name__ == '__main__':
      smtp = smtplib.SMTP()
      smtp.connect(smtpserver, 25)
      smtp.login(user, password)
      smtp.sendmail(sender, receiver, msg.as_string())
      smtp.quit()

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马