#!/usr/bin/env/python3
# -*- coding:utf-8 -*-
'''author:leo
date&time:2020/5/28 and 15:44
project:python3
filename:20200528_email.py
description:
qq郵件傳送
'''import smtplib # smtplib 用於郵件的發信動作
from email.mime.text import mimetext # email 用於構建郵件內容
from email.header import header # 用於構建郵件頭
from 抵押貸專案sit.library.basic import basic
import time, random
logtime = time.strftime('%y%m%d_%h:%m:%s', time.localtime(time.time()))
curtime = time.strftime('%y%m%d %h%m%s', time.localtime(time.time()))
class tx_email():
def __init__(self):
self.logtime = time.strftime('%y%m%d_%h:%m:%s', time.localtime(time.time()))
self.curtime = time.strftime('%y%m%d %h%m%s', time.localtime(time.time()))
self.nowdate_8, self.nowtime_6, self.random_3 = self.curtime.split(" ")[0], self.curtime.split(" ")[1], str(random.randint(100, 999))
def send_email(self, title='python_title', message='python test message', send_status=false):
if send_status == true:
# 發信方的資訊:發信郵箱,qq 郵箱授權碼
from_addr = '[email protected]'
password = '123456'
# 收信方郵箱
to_addr = '[email protected]'
# 發信伺服器
smtp_server = 'smtp.qq.com'
# 郵箱正文內容,第乙個引數為內容,第二個引數為格式(plain 為純文字),第三個引數為編碼
msg = mimetext(message, 'plain', 'utf-8')
# 郵件頭資訊
msg['from'], msg['to'], msg['subject'] = header(from_addr), header(to_addr), header(title)
# 開啟發信服務,這裡使用的是加密傳輸
server = smtplib.smtp_ssl()
server.connect(smtp_server, 465)
# 登入發信郵箱
server.login(from_addr, password)
# 傳送郵件
server.sendmail(from_addr, to_addr, msg.as_string())
# 關閉伺服器
server.quit()
basic().write_txt(filename=f"run_file\\_runlog.txt", mode="a+", log_info="(email:)" + "----郵件傳送成功----" + "\n(messg:)" + str(f""))
print(f"\n----郵件傳送成功----")
if __name__ == '__main__':
# # 郵件通知
tx_message = "test"
tx_email().send_email(title=f"測試資料:", message=f"")
Web 介面測試 Python3
usr bin env python3 coding utf 8 author leo date time 2020 2 24 and 17 29 project python3 filename tmp comment.py description 1.快速構造請求頭 1 2 1 3 1 kwar...
python3介面程式設計 Python3程式設計技巧
in 1 fromrandom import randint in 2 data randint 10,10 for in range 10 in 3 data out 3 3,4,3,4,7,2,4,1,7,9 過濾列表中的負數 in 9 list filter lambda x x 0,data...
python3呼叫http介面
最近在寫python呼叫介面的服務,寫了乙個呼叫介面的函式,如下 param inputdata 單個樣本的輸入引數,是json格式的資料 return 單個樣本的探真查詢變數結果資料 呼叫介面 介面有正確的資料才讀入,否則為空 if res code 0000 res data json.load...