群发邮件注意:三处标红的地方
# -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header from email.mime.image import MIMEImage # 第三方 SMTP 服务 mail_host="smtp.qq.com" #设置服务器 mail_user="xxx@qq.com" #用户名 mail_pass="xxxxxx" #口令 sender = 'xxx@qq.com' receivers = ['123@qq.com','456@qq.com','789@qq.com','987@qq.com','546@qq.com','321@qq.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱 msgRoot = MIMEMultipart('related') msgRoot['From'] = Header("发送人", 'utf-8') msgRoot['To'] = ','.join(receivers)#注意 subject = '主题' msgRoot['Subject'] = Header(subject, 'utf-8') msgAlternative = MIMEMultipart('alternative') msgRoot.attach(msgAlternative) mail_msg = """ 发送信息内容 """ msgAlternative.attach(MIMEText(mail_msg, 'html', 'utf-8')) try: smtpObj = smtplib.SMTP_SSL(mail_host, 465) smtpObj.login(mail_user,mail_pass) smtpObj.sendmail(sender, receivers, msgRoot.as_string()) print "邮件发送成功" except smtplib.SMTPException: print "Error: 无法发送邮件"