怎么在python3.5中使用email發(fā)送郵件-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)怎么在python3.5 中使用email發(fā)送郵件,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供米易網(wǎng)站建設(shè)、米易做網(wǎng)站、米易網(wǎng)站設(shè)計(jì)、米易網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、米易企業(yè)網(wǎng)站模板建站服務(wù),十余年米易做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。python有哪些常用庫

python常用的庫:1.requesuts;2.scrapy;3.pillow;4.twisted;5.numpy;6.matplotlib;7.pygama;8.ipyhton等。

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 href="http://blog.csdn.net/wjoxoxoxxx" 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)化測試報(bào)告'
 send_mail(subject)

關(guān)于怎么在python3.5 中使用email發(fā)送郵件就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

網(wǎng)頁名稱:怎么在python3.5中使用email發(fā)送郵件-創(chuàng)新互聯(lián)
當(dāng)前URL:http://muchs.cn/article42/dsheec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、微信小程序關(guān)鍵詞優(yōu)化、定制開發(fā)、企業(yè)網(wǎng)站制作電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)