selenium+python 发送邮件
一、准备
给发件人开通POP3/SMTP IMAP/SMTP服务,获得授权密码
授权码:如上图16位
二、用法
整个发邮件代码如下:
import smtplib
from datetime import time
from email.mime.multipart
import MIMEMultipart
from email.mime.text import MIMEText
class EmailManager:
def send_email(self):
# now = time.strftime("%Y-%m-%d
%H-%M", time.localtime())
#定义SMTP服务器
smtpserver = 'smtp.qq.com'
#发送邮件的用户名和客户端密码(就是授权密码)
username = '75603083@qq.com'
passwd = 'xxxxxxxxxxxxxxx' #授权密码
#接收邮件的邮箱
receiver = '75603083@qq.com'
#创建邮件对象
message =
MIMEMultipart('related')
#邮件主题
subject = 'ShopXO商城系统自动化测试报告'
fujian = MIMEText(open('D:/wuxx/PycharmProjects/Shop_V21/reports/result_2022-03-03
15-22.html','rb').read(),'html','utf-8')
#把邮件的信息组装到邮件对象里面
message['from']=username
message['to']=receiver
message['subject']=subject
message.attach(fujian)
#登录smtp服务器并发送邮件
smtp =
smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username,passwd)
smtp.sendmail(username,receiver,message.as_string())
smtp.quit()
if __name__ == '__main__':
EmailManager().send_email()