python 发送邮件接口
python 发送邮件接口
def send_mail(content): subject = " UI 自动化测试报告" # 邮件标题 sender = "*****" # 发送方 to_recver = ["****","****"] #接受者 cc_recver = ["***","****"] #抄送者reciver = to_recver + cc_recver password = "****" # 邮箱密码 message = MIMEText(content, "plain", "utf-8") # content 发送内容 "plain"文本格式 utf-8 编码格式 message['Subject'] = subject # 邮件标题 message['From'] = sender message['To'] = ";".join(to_recver) message['Cc'] = ";".join(cc_recver) # smtp = smtplib.SMTP_SSL("smtp.163.com", 994) # 实例化smtp服务器 smtp = smtplib.SMTP_SSL("smtp.exmail.qq.com", 465) smtp.login(sender, password) # 发件人登录 smtp.sendmail(sender, reciver, message.as_string()) # as_string 对 message 的消息进行了封装 smtp.close()
调用接口
send_mail("UI 自动化测试")