国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python3.5 email實現發送郵件功能

2020-02-23 00:11:36
字體:
來源:轉載
供稿:網友

本文實例為大家分享了python3.5 email發送郵件的具體代碼,供大家參考,具體內容如下

直接套用代碼即可

from email.mime.text import MIMETextfrom email.mime.image import MIMEImagefrom email.mime.base import MIMEBasefrom email.mime.multipart import MIMEMultipartfrom email import encodersimport smtplibimport timedef send_mail(subject): email_host = '' # 服務器地址 sender = '' # 發件人 password = '' # 密碼,如果是授權碼就填授權碼 receiver = '' # 收件人 msg = MIMEMultipart() msg['Subject'] = subject # 標題 msg['From'] = '' # 發件人昵稱 msg['To'] = '' # 收件人昵稱 signature = '''/n/t this is auto test report!/n/t you don't need to follow''' # text = MIMEText(signature, 'plain') # 簽名 # msg.attach(text) # 正文-圖片 只能通過html格式來放圖片,所以要注釋25,26行 mail_msg = '''<p>/n/t this is auto test report!</p><p>/n/t you don't need to follow</p><p><a  rel="external nofollow" >我的博客:</a></p><p>截圖如下:</p><p><img src="cid:image1"></p>''' msg.attach(MIMEText(mail_msg, 'html', 'utf-8')) # 指定圖片為當前目錄 fp = open(r'111.jpg', 'rb') msgImage = MIMEImage(fp.read()) fp.close() # 定義圖片 ID,在 HTML 文本中引用 msgImage.add_header('Content-ID', '<image1>') msg.attach(msgImage) ctype = 'application/octet-stream' maintype, subtype = ctype.split('/', 1) # 附件-圖片 image = MIMEImage(open(r'111.jpg', 'rb').read(), _subtype=subtype) image.add_header('Content-Disposition', 'attachment', filename='img.jpg') msg.attach(image) # 附件-文件 file = MIMEBase(maintype, subtype) file.set_payload(open(r'320k.txt', 'rb').read()) file.add_header('Content-Disposition', 'attachment', filename='test.txt') encoders.encode_base64(file) msg.attach(file) # 發送 smtp = smtplib.SMTP() smtp.connect(email_host, 25) smtp.login(sender, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit() print('success')if __name_- == '__main__': now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) subject = now + '自動化測試報告' send_mail(subject)

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 曲麻莱县| 汶上县| 吉安市| 佛坪县| 团风县| 湖口县| 远安县| 涞源县| 体育| 定结县| 白沙| 梅河口市| 澄城县| 临夏县| 镇坪县| 安化县| 友谊县| 武强县| 临沧市| 墨竹工卡县| 英吉沙县| 菏泽市| 泾源县| 衡阳县| 信丰县| 云安县| 富裕县| 宕昌县| 胶州市| 香格里拉县| 页游| 会宁县| 广丰县| 平顺县| 且末县| 儋州市| 渭源县| 策勒县| 南阳市| 朝阳市| 齐齐哈尔市|