国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

python 自動監控最新郵件并讀取的操作

瀏覽:28日期:2022-06-26 08:18:10

我就廢話不多說了,大家還是直接看代碼吧~

#zmail庫:可以用幾行代碼幫我們收取一封郵件import zmail#輸入賬號和密碼server=zmail.server(’[email protected]’,’jie110341’)#獲取最新的一封郵件mail=server.get_latest()#讀取郵件#zmail.show(mail)#讀取郵件的部分內容print(mail[’subject’])......#讀取附件 郵件 存放路徑 如果有同名文件則覆蓋zmail.save_acctachment(mail,target_path=None,overwrite=True)

需要在電腦上下載zmail庫

補充:Python郵箱實施監控電腦

我就廢話不多說了,大家還是直接看代碼吧~

import smtplibimport poplibimport emailfrom email.mime.application import MIMEApplicationfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextfrom email.header import decode_headerdef send_email(account, password, email_title, send_text='', file_names=None, file_dir='.'): msg = MIMEMultipart() # msg = MIMEText(HTML, ’html’) -- 只能發送文本內容 content = MIMEText(send_text, 'plain', 'utf-8') msg.attach(content) # 文件類型 if isinstance(file_names, list): for file_name in file_names: send_file_path = file_dir + '/' + file_name part = MIMEApplication(open(send_file_path, ’rb’).read()) part.add_header(’Content-Disposition’, ’attachment’, filename=file_name) msg.attach(part) elif isinstance(file_names, str): send_file_path = file_dir + '/' + file_names part = MIMEApplication(open(send_file_path, ’rb’).read()) part.add_header(’Content-Disposition’, ’attachment’, filename=file_names) msg.attach(part) # msg[’from’],msg[’to’]接收端顯示的發件人與收件人 msg[’from’] = '奧巴馬@163.com' msg[’to’] = account msg[’subject’] = email_title try: server = smtplib.SMTP() server.connect(’smtp.163.com’) server.login(account, password) # from_addr:發送地址; to_addrs:接收地址(字符串列表) server.sendmail(account, msg[’to’].split(), msg.as_string()) except Exception as e: print(e)# 獲取郵件標題def get_email_subject(addr, password): # 設置連接網址,獲取pop3協議的郵件讀取對象 read = poplib.POP3(’pop.163.com’, timeout=3600) # 輸入郵件地址與郵件登錄密碼 read.user(addr) # 163郵箱用戶名 read.pass_(password) # 163郵箱設置中的客戶端授權密碼 # allEmails = (totalNum, totalSize) # 讀取郵件信息(郵件總數,郵件尺寸) total_num, total_size = read.stat() # top(which,howmuch) # 獲取最新的一封郵件(第幾封郵件,獲取多少封) top_email = read.top(total_num, 1) # print('***** start *****n接收的數據為: {}n***** end *****n'.format(top_email)) # # print('***** start *****n[解碼前]獲取的初始郵件內容: {}n***** end *****n'.format(top_email[1])) # 解碼郵件信息,將解碼后的郵件信息存入tmp tmp = [] for s in top_email[1]: tmp.append(s.decode()) # print('***** start *****n[解碼后]的郵件內容為: {}n***** end *****n'.format(tmp)) # 將解碼后的郵件內容拼接為字符串 email_str = ’n’.join(tmp) # 將字符串類型解析為Message類型 message = email.message_from_string(email_str) # print('***** start *****n' # '[解碼前]的郵件字符串內容為: [數據類型]{}n{}n' # '--------------------------------------------n' # '[解碼后]的郵件字符串內容為: [數據類型]{}n{}n' # '***** end *****n' # .format(type(email_str), email_str, type(message), message)) # 獲取郵件主題 subject_str = message[’subject’] # print('***** start *****n[解碼前]郵件標題: {}n***** end *****n'.format(subject_str)) subject = decode_header(subject_str) # print('***** start *****n[解碼后]郵件標題: {}n***** end *****n'.format(subject)) content = subject[0][0] enc_type = subject[0][1] if enc_type: subject_decode = content.decode(enc_type) else: subject_decode = content return subject_decode, read, total_num

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 91久久亚洲精品国产一区二区 | 久久综合狠狠综合久久97色 | 在线有码 | 最新久久免费视频 | 欧美一区亚洲二区 | 久草视频在线免费 | 成人网免费看 | 国产精品一级香蕉一区 | 久久久亚洲欧美综合 | 毛片在线全部免费观看 | 青青草国产免费久久久91 | 国产精品九九九久久九九 | 国产精品二 | 久久91精品国产91 | 久久精品女人毛片国产 | 成人涩涩屋福利视频 | 我要看a级毛片 | 美女网站免费观看视频 | 中文字幕无线精品乱码一区 | 国产成人综合亚洲亚洲欧美 | 成人免费在线网站 | 国产成人免费福利网站 | 日韩一级片免费看 | 韩国黄色一级毛片 | 国内精品福利在线视频 | 在线播放免费播放av片 | 国产伦精品一区三区视频 | 日韩欧美一及在线播放 | 天堂色视频 | 亚洲人成网站色7799在线观看 | 日本色哟哟 | 亚洲综合色就色手机在线观看 | 人人操美女 | 国产孕妇孕交视频 | 欧美一区二区aa大片 | 国产成年 | 免费久| 波多野结衣免费视频观看 | 久久成人精品免费播放 | 黄色毛片视频网站 | 免费看欧美一级特黄a大片一 |