python+selenium之郵件發送


import smtplib                       #發送郵件模塊
from email.mime.text import MIMEText #定義郵件內容
from email.header import Header      #定義郵件標題

#發送郵件服務器
smtpserver='smtp.163.com'

#發送郵箱用戶名和密碼
user='test_pythonmail@163.com'
password='cao15036214043'

#發送和接收郵箱
sender='test_pythonmail@163.com'
receive='1219853367@qq.com'

# 發送郵件主題和內容
subject='Web Selenuim 自動化測試報告'
content='<html><h1 style="color:red">我要自學網,自學成才!</h1></html>'

#HTML郵件正文
msg=MIMEText(content,'html','utf-8')
msg['subject']=Header(subject,'utf-8')
msg['From']='test_pythonmail@163.com'
msg['To']='1219853367@qq.com'

#SSL協議端口號要使用465
smtp=smtplib.SMTP_SSL(smtpserver,465)

#向用戶標識用戶身份
smtp.helo(smtpserver)
#服務器返回結果確認
smtp.ehlo(smtpserver)
#登錄郵箱服務器用戶名和密碼
smtp.login(user,password)


print("Start send Email....")
smtp.sendmail(sender,receive,msg.as_string())
smtp.quit()
print("Send Email end!")

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM