自动化测试学习之--Python 邮件同时发送多人

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/juhua2012/article/details/89165286
# 案例:使用163邮箱来结合smtp模块发送邮件 邮件同时发送多人
import smtplib  #发送邮件模块
from email.mime.text import MIMEText  #定义邮件内容
from email.header import Header       #定义邮件标题

#发送邮箱服务器
smtpserver='smtp.163.com'

#发送邮箱用户名密码(密码是授权密码)
user='[email protected]'
password='******'

#发送和接收邮箱
sender=''[email protected]'
receives=['[email protected]','[email protected]']

#发送邮件主题和内容
subject='Web Selenium 自动化测试报告'
content='<html><h1 style="color:red">收到邮件没!</h1></html>'

#HTML邮件正文
msg=MIMEText(content,'html','utf-8')
msg['Subject']=Header(subject,'utf-8')
msg['From']=sender
msg['To']=','.join(receives)

#SSL协议端口号要使用465
smtp=smtplib.SMTP_SSL(smtpserver,465)

#HELO 向服务器标识用户身份
smtp.helo(smtpserver)
#服务器返回结果确认
smtp.ehlo(smtpserver)
#登录邮箱服务器用户名和密码
smtp.login(user,password)

print("开始发送邮件...")
smtp.sendmail(sender,receives,msg.as_string())
smtp.quit()
print("邮件发送完成!")

猜你喜欢

转载自blog.csdn.net/juhua2012/article/details/89165286