发送邮件(多人)

#SMTP:简单邮件传输协议,属于TCP/IP协议
#smtplib模块,发送邮件
#email模块,负责构造邮件
import smtplib #发送邮件模块
from email.mime.text import MIMEText #定义邮件内容
from email.header import Header #定义邮件标题
from email.mime.multipart import MIMEMultipart #定义邮件附件
#发送邮箱服务器
smtpserver='smtp.qq.com'
#设置用户名和密码
user='****@qq.com'
password = '****' #指的是授权密码不是登录密码
#发送和接收邮箱
sender='***@qq.com'
receive="***@126.com,****@qq.com" #多个收件人
#发送邮件主题和内容
subject="Selenium 自动化测试"
content='<html><h1 style="color:red">我要自学selenium,努力加油坚持</h></html>'
#定义HTML邮件正文
msg=MIMEText(content,'html','utf-8')
msg["Subject"]=Header(subject,'utf-8')
msg['From']='****@qq.com'
msg['To']='****@126.com'

#ssl协议端口号是465、587
smtp=smtplib.SMTP_SSL(smtpserver,465)
#向服务器标识用户身份
smtp.helo(smtpserver)
#服务器返回结果却认
smtp.ehlo(smtpserver)
#登录邮箱服务器用户名和密码
smtp.login(user,password)

print('Start send Email...')
#发送,发送多人要用到split分割成列表
smtp.sendmail(sender,receive.split(','),msg.as_string())
smtp.quit()
print('Send Email end!')

猜你喜欢

转载自www.cnblogs.com/Luafair/p/9999506.html
今日推荐