然后选择Windows 电脑或者其它设备生成
有两个有用的信息一个是密码passwd ,一个是smtplib.SMTP_SSL(“smtp.feishu.cn”, 465)这里面的内容
import smtplib
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
msg_from = 'xxx@xxx.cn' # 发送方邮箱
passwd = 'xxxxxxxxxx' # 填入发送方邮箱的授权码
msg_to = 'xxx@xxx.cn' # 收件人邮箱,我是自己发给自己
text_content = "test fail!!!" # 发送的邮件内容
def send_email(self, msg_from, passwd, msg_to, text_content, file_path=None):
msg = MIMEMultipart()
subject = "自动化测试结果" # 主题
text = MIMEText(text_content)
msg.attach(text)
file_path = r'xxx1.txt' #如果需要添加附件,就给定路径
if file_path: # 最开始的函数参数我默认设置了None ,想添加附件,自行更改一下就好
docFile = file_path
docApart = MIMEApplication(open(docFile, 'rb').read())
docApart.add_header('Content-Disposition', 'attachment', filename=docFile)
msg.attach(docApart)
docFile = r'xxxx2.txt'
docApart = MIMEApplication(open(docFile, 'rb').read())
docApart.add_header('Content-Disposition', 'attachment', filename=docFile)
msg.attach(docApart)
print('发送附件到', msg_to)
msg['Subject'] = subject
msg['From'] = msg_from
msg['To'] = msg_to
try:
s = smtplib.SMTP_SSL("smtp.feishu.cn", 465)
s.login(msg_from, passwd)
s.sendmail(msg_from, msg_to, msg.as_string())
print("发送成功")
except smtplib.SMTPException as e:
print("发送失败")
finally:
s.quit()
send_email(msg_from, passwd, msg_to, text_content)