国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

如何利用python發送郵件

瀏覽:2日期:2022-07-10 08:00:04

一、zmial發送郵件

zmial是第三方庫,需進行安裝

pip install zmail

完成后,來給發一封郵件

subject:標題content_text:內容

import zmail server = zmail.server(’發件人郵箱地址’,’授權碼’) server.send_mail(’收件人郵箱地址’,{’subject’:’Hello!’,’content_text’:’By zmail.’})

二、smtplib發送郵件

import smtplibfrom email.mime.text import MIMEText#--------發件相關參數--------smtpserver='smtp.qq.com' #連接服務器port = 465 #端口sender = '741841851@qq.com'#賬號psw = 'xxxxx'#密碼 授權碼receiver='741841851@qq.com'#接收人#--------編輯郵件內容--------subject='qq郵件主題'body= ’<p>這個是發送的qq郵件</p>’msg = MIMEText(body,’html’,’utf-8’)msg[’from’]=sendermsg[’to’]=’741841851@qq.com’msg[’subject’]=subject#-----------test_email-------smtp = smtplib.SMTP_SSL(smtpserver,port)#連接服務器smtp.login(sender,psw)#登錄smtp.sendmail(sender,receiver,msg.as_string())#發送郵件smtp.quit()

三、發送帶附件的郵件

import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimport ossmtpserver=’smtp.qq.com’port =465sender=’741841851@qq.com’psw = ’xxxx’recevier = '741841851@qq.com'filenamepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),’ceshi.html’)with open(filenamepath,’rb’) as f: mail_body=f.read().decode(’utf-8’)msg = MIMEMultipart()msg[’from’]=sender#發件人msg[’to’]=recevier#收件人msg[’subject’]=’這是我的主題99’#主題# 正文body = MIMEText(mail_body,’html’,’utf-8’)msg.attach(body)#附件att = MIMEText(mail_body,’base64’,’gbk’)#用utf-8會出現亂碼att[’Content-Type’]=’application/octet-stream’att[’Content-Disposition’]=’attachment;filename='test_report.html'’msg.attach(att)####發送郵件try: smtp = smtplib.SMTP() smtp.connect(smtpserver)#連接服務器 smtp.login(sender,psw)#登錄except: smtp = smtplib.SMTP_SSL(smtpserver,port) smtp.login(sender,psw)#登錄smtp.sendmail(sender,recevier,msg.as_string())#發送郵件smtp.quit()

以上就是如何利用python發送郵件的詳細內容,更多關于python 發送郵件的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 安阳市| 通州区| 广安市| 宣武区| 华阴市| 满洲里市| 鄂托克旗| 丰顺县| 铁力市| 会理县| 林西县| 东山县| 宜君县| 湟中县| 金塔县| 沙河市| 内丘县| 虹口区| 呼图壁县| 河北区| 六枝特区| 新疆| 尼玛县| 女性| 梓潼县| 台山市| 峨边| 嵩明县| 绍兴县| 温泉县| 辉县市| 微博| 德庆县| 迭部县| 黄平县| 额敏县| 喀喇| 汾西县| 洪泽县| 万州区| 高陵县|