欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python3.5 email實(shí)現(xiàn)發(fā)送郵件功能

 更新時(shí)間:2018年05月22日 11:53:00   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了python3.5 email實(shí)現(xiàn)發(fā)送郵件功能,包含txt、圖片、HTML、附件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python3.5 email發(fā)送郵件的具體代碼,供大家參考,具體內(nèi)容如下

直接套用代碼即可

from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email import encoders
import smtplib
import time


def send_mail(subject):
 email_host = '' # 服務(wù)器地址
 sender = '' # 發(fā)件人
 password = '' # 密碼,如果是授權(quán)碼就填授權(quán)碼
 receiver = '' # 收件人

 msg = MIMEMultipart()
 msg['Subject'] = subject # 標(biāo)題
 msg['From'] = '' # 發(fā)件人昵稱
 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'))
 # 指定圖片為當(dāng)前目錄
 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)

 # 發(fā)送
 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 + '自動(dòng)化測(cè)試報(bào)告'
 send_mail(subject)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Linux下python3.6.1環(huán)境配置教程

    Linux下python3.6.1環(huán)境配置教程

    這篇文章主要為大家詳細(xì)介紹了Linux下python3.6.1環(huán)境配置教程 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • python 中yaml文件用法大全

    python 中yaml文件用法大全

    本文主要是總結(jié)yaml常用的一些數(shù)據(jù)形式,對(duì)于我們正常的項(xiàng)目使用,已經(jīng)足夠用了,接下來通過本文給大家分享python 中yaml文件用法,需要的朋友參考下吧
    2021-07-07
  • python中celery的基本使用詳情

    python中celery的基本使用詳情

    這篇文章主要介紹了python中celery的基本使用詳情,Celery 是由Python 編寫的簡(jiǎn)單,靈活,可靠的用來處理大量信息的分布式系統(tǒng),它同時(shí)提供操作和維護(hù)分布式系統(tǒng)所需的工具。Celery 專注于實(shí)時(shí)任務(wù)處理,支持任務(wù)調(diào)度
    2022-09-09
  • anaconda?navigator打不開問題的解決方法

    anaconda?navigator打不開問題的解決方法

    在使用python的發(fā)行版anaconda時(shí),常常需要根據(jù)自己的項(xiàng)目安裝新的庫,下面這篇文章主要給大家介紹了關(guān)于anaconda?navigator打不開問題的解決方法,需要的朋友可以參考下
    2022-12-12
  • 完美解決ARIMA模型中plot_acf畫不出圖的問題

    完美解決ARIMA模型中plot_acf畫不出圖的問題

    這篇文章主要介紹了完美解決ARIMA模型中plot_acf畫不出圖的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • python 根據(jù)pid殺死相應(yīng)進(jìn)程的方法

    python 根據(jù)pid殺死相應(yīng)進(jìn)程的方法

    下面小編就為大家?guī)硪黄猵ython 根據(jù)pid殺死相應(yīng)進(jìn)程的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • Pytorch1.5.1版本安裝的方法步驟

    Pytorch1.5.1版本安裝的方法步驟

    這篇文章主要介紹了Pytorch1.5.1版本安裝的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • 詳解Python3中yield生成器的用法

    詳解Python3中yield生成器的用法

    這篇文章主要介紹了詳解Python3中yield生成器的用法,是Python入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-08-08
  • Python基于pygame實(shí)現(xiàn)的彈力球效果(附源碼)

    Python基于pygame實(shí)現(xiàn)的彈力球效果(附源碼)

    這篇文章主要介紹了Python基于pygame實(shí)現(xiàn)的彈力球效果,涉及pygame圖形動(dòng)態(tài)操作的相關(guān)的技巧,并附帶了完整的源碼供讀者下載參考,需要的朋友可以參考下
    2015-11-11
  • pycharm通過anaconda安裝pyqt5的教程

    pycharm通過anaconda安裝pyqt5的教程

    PyCharm是一種Python IDE,帶有一整套可以幫助用戶在使用Python語言開發(fā)時(shí)提高其效率的工具,這篇文章主要介紹了pycharm通過anaconda來安裝pyqt5的教程,需要的朋友可以參考下
    2020-03-03

最新評(píng)論