使用Python以HTML格式发送测试用例结果可以通过以下步骤实现:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
sender = 'your_email@example.com'
receiver = 'recipient_email@example.com'
msg = MIMEMultipart('alternative')
msg['Subject'] = '测试用例结果'
msg['From'] = sender
msg['To'] = receiver
with open('test_results.html', 'r') as file:
test_results = file.read()
html = MIMEText(test_results, 'html')
msg.attach(html)
smtp_server = 'smtp.example.com'
smtp_port = 587
smtp_username = 'your_email@example.com'
smtp_password = 'your_password'
try:
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
server.login(smtp_username, smtp_password)
server.sendmail(sender, receiver, msg.as_string())
server.quit()
print('邮件发送成功!')
except Exception as e:
print('邮件发送失败:', str(e))
以上代码将测试用例结果以HTML格式作为邮件正文发送给指定的收件人。你可以将代码中的发件人、收件人、SMTP服务器、端口、用户名和密码替换为你自己的信息。
推荐的腾讯云相关产品:腾讯企业邮件(https://cloud.tencent.com/product/exmail)可以用于发送邮件,腾讯云函数(https://cloud.tencent.com/product/scf)可以用于部署和运行Python代码。
领取专属 10元无门槛券
手把手带您无忧上云