獲取郵件伺服器
email_host = "smtp.163.com"
send_user = "******@163.com"
password = "***x123456"
定義傳送郵件主體
def send_mail(self,user_list,sub,content):
user = "******"+""
message = mimetext(content,_subtype='plain',_charset='utf-8')
message['subject'] = sub
message['from'] = user
message['to'] = ";".join(user_list)
server = smtplib.smtp()
server.connect(email_host)
server.login(send_user,password)
server.sendmail(user,user_list,message.as_string())
server.close()
定義傳送郵件的主體方法,統計傳送郵件失敗的個數,和傳送郵件成功個數
def send_main(self,pass_list,fail_list):
pass_num = float(len(pass_list))
fail_num = float(len(fail_list))
count_num = pass_num+fail_num
pass_result = "%.2f%%" %(pass_num/count_num*100)
fail_result = "%.2f%%" %(fail_num/count_num*100)
user_list = ['[email protected]']
sub = "介面自動化測試報告"
content = "此次一共執行介面個數為%s個,通過個數為%s個,失敗個數為%s,通過率為%s,失敗率為%s" %
(count_num,pass_num,fail_num,pass_result,fail_result )
self.send_mail(user_list,sub,content)
if __name__ == '__main__':
sen = sendemail()
sen.send_main([1,2,3,4],[2,3,4,5,6,7])
利用python傳送郵件技術解析
1 smtplib模組 import smtplib smtp smtplib.smtp smtp.connect smtp.163.com,25 smtp.login username,password smtp.sendmail sender,receiver,msg.as string smt...
python3接收 解析郵件
python3可以使用poplib.pop3進行郵件接收,具體如下 import poplib from email.parser import parser def get email email,password,host mail.163.com connect to pop3 server ...
Python傳送郵件實現基礎解析
一 python郵件模組簡介 email模組屬於內建模組,用來自定義郵件的中文 主題 日期 附件等資訊 smtplib模組屬於內建模組,它對smtp協議進行了簡單的封裝,能實現郵件傳送。二 郵件傳送步驟 建立smtp的操作物件並連線smtp目標伺服器,可以是163 qq等 使用自己的賬號登入目標伺服...