asp.net+大檔案上傳
阿新 • • 發佈:2021-12-23
1.使用前先要安裝 yagmail
pip install yagmail -i https://pypi.douban.com/simple
2.使用QQ郵箱傳送郵件,使用的是授權碼,需要先到QQ郵箱申請授權碼。
郵箱設定-->賬戶
3.yagmail 模組傳送郵件更加簡單,四行程式碼
# -*- encoding: utf-8 -*- import yagmail def E_mali_jj(fr,key,etype,text,to,attachments): ''' :param fr: 傳送郵箱 :param key: 授權碼 :param etype: 郵件型別 :param text: 文字 :param to: 接受郵箱 :param attachments: 附件檔案地址,空則填'' :return:''' # 連結郵箱伺服器 yag=yagmail.SMTP(user=fr,password=key,host=etype) # 郵箱正文 contents=[text] # 傳送郵件 yag.send(to=to,subject='郵件標題',contents=contents, attachments=attachments) #subject 標題 yag.close() print("郵件傳送成功") if __name__ == '__main__': E_mali_jj("[email protected]", "gwheybuaamrqbihh", 'smtp.qq.com', "郵件正文內容", "[email protected]", "E:\\proto_code\\Roshan-01-microscript-proto_test-master-src\\src\\report\\report.html")
3.1傳送郵件給多個人
郵件傳送給多個人,將接受的郵箱放在列表中即可
# 傳送郵件 yag.send(to = ['[email protected]','[email protected]', '10111213@qq.com'], subject='subject', contents = contents, attachments="")
4.傳送郵件帶附件
# -*- coding:utf-8 -*- import yagmail yag = yagmail.SMTP( user="[email protected]", password="kayzilfyziulbhbb1", host='smtp.qq.com') """ user: 傳送的郵箱 password: 授權碼 """ # 郵箱正文 contents = ['測試傳送郵件'] # 附件 attachments = "D:\\code\\0906\\api_test009\\report\\report.html" # 傳送郵件 try: yag.send(to = '[email protected]', subject='subject', contents = contents, attachments=attachments) except Exception as e : print("Error: 抱歉!傳送郵件失敗。", e) """ to : 接收者 subject : 郵件主題 contents: 正文 attachments: 附件 """ yag.close()
5.封裝
# -*- coding:utf-8 -*- import yagmail def send(user, password, receiver): yag = yagmail.SMTP( user=user, password=password, host='smtp.qq.com') """ user: 傳送的郵箱 password: 授權碼 """ # 郵箱正文 contents = ['測試傳送郵件'] # 附件 attachments = "D:\\code\\0906\\api_test009\\report\\report.html" # 傳送郵件 try: yag.send(to=receiver, subject='subject', contents = contents, attachments=attachments) except Exception as e : print("Error: 抱歉!傳送郵件失敗。", e) """ to : 接收者 subject : 郵件主題 contents: 正文 attachments: 附件 """ yag.close() if __name__ == '__main__': send("[email protected]", "kayzilfyziulbhbb1", "[email protected]")
作者:小林同學_Scorpio
出處:https://www.cnblogs.com/xiaolintongxue1/
本部落格所有文章僅用於學習、分享和交流目的,歡迎非商業性質轉載。
博主的文章沒有高度、深度和廣度,只是湊字數,做筆記。由於博主的水平不高,不足和錯誤之處在所難免,希望大家能夠批評指出。
博主是利用參考、引用、抄襲、複製和貼上等多種方式打造成自己的文章,請原諒博主成為一個無恥的文件搬運工!