最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python 七種郵件內(nèi)容發(fā)送方法實例

 更新時間:2014年04月22日 10:00:06   作者:  
這篇文章主要介紹了python 七種郵件內(nèi)容發(fā)送方法實例,需要的朋友可以參考下

一、文件形式的郵件

復(fù)制代碼 代碼如下:
#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header

sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***'

msg = MIMEText('你好','text','utf-8')#中文需參數(shù)‘utf-8',單字節(jié)字符不需要
msg['Subject'] = Header(subject, 'utf-8')

smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

二、HTML形式的郵件

復(fù)制代碼 代碼如下:

#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.text import MIMEText

sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***'

msg = MIMEText('</pre>
<h1>你好</h1>
<pre>','html','utf-8')

msg['Subject'] = subject

smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

三、帶圖片的HTML郵件

復(fù)制代碼 代碼如下:

#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage

sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***'

msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'test message'

msgText = MIMEText('<b>Some <i>HTML</i> text</b> and an image.
<img alt="" src="cid:image1" />
good!','html','utf-8')
msgRoot.attach(msgText)

fp = open('h:\\python\\1.jpg', 'rb')
msgImage = MIMEImage(fp.read())
fp.close()

msgImage.add_header('Content-ID', '')
msgRoot.attach(msgImage)

smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msgRoot.as_string())
smtp.quit()

四、帶附件的郵件

復(fù)制代碼 代碼如下:
#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage

sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***'

msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'test message'

#構(gòu)造附件
att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="1.jpg"'
msgRoot.attach(att)

smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msgRoot.as_string())
smtp.quit()

五、群郵件

復(fù)制代碼 代碼如下:
#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.text import MIMEText

sender = '***'
receiver = ['***','****',……]
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***'

msg = MIMEText('你好','text','utf-8')

msg['Subject'] = subject

smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

六、各種元素都包含的郵件
復(fù)制代碼 代碼如下:
#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage

sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***'

# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"

# Create the body of the message (a plain-text and an HTML version).
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
html = """\

 
Hi!

       How are you?

       Here is the <a >link</a> you wanted.

 

"""

# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')

# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
#構(gòu)造附件
att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="1.jpg"'
msg.attach(att)

smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

七、基于SSL的郵件

復(fù)制代碼 代碼如下:
#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header
sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***'

msg = MIMEText('你好','text','utf-8')#中文需參數(shù)‘utf-8',單字節(jié)字符不需要
msg['Subject'] = Header(subject, 'utf-8')

smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.set_debuglevel(1)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

相關(guān)文章

  • Python 性能優(yōu)化技巧總結(jié)

    Python 性能優(yōu)化技巧總結(jié)

    代碼優(yōu)化能夠讓程序運行更快,它是在不改變程序運行結(jié)果的情況下使得程序的運行效率更高,根據(jù) 80/20 原則,實現(xiàn)程序的重構(gòu)、優(yōu)化、擴展以及文檔相關(guān)的事情通常需要消耗 80% 的工作量。優(yōu)化通常包含兩方面的內(nèi)容:減小代碼的體積,提高代碼的運行效率。
    2016-11-11
  • python不換行之end=與逗號的意思及用途

    python不換行之end=與逗號的意思及用途

    在python中我們偶爾會用到輸出不換行的效果,python2中使用逗號,即可,而python3中使用end=''來實現(xiàn)的,這里簡單為大家介紹一下,需要的朋友可以參考下
    2017-11-11
  • python 音頻處理重采樣、音高提取的操作方法

    python 音頻處理重采樣、音高提取的操作方法

    這篇文章主要介紹了python 音頻處理重采樣、音高提取,本文給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧
    2024-08-08
  • 使用Python插入SVG到PDF文檔中的方法示例

    使用Python插入SVG到PDF文檔中的方法示例

    將SVG(可縮放矢量圖形)文件插入到PDF(便攜式文檔格式)文件中不僅能夠保留SVG圖像的矢量特性,確保圖像在任何分辨率下都保持清晰,使得技術(shù)文檔、手冊、報告等內(nèi)容更加豐富多樣且易于傳播,本文將介紹如何使用Python插入SVG文件到PDF文檔中,需要的朋友可以參考下
    2024-08-08
  • Python解析、提取url關(guān)鍵字的實例詳解

    Python解析、提取url關(guān)鍵字的實例詳解

    今天小編就為大家分享一篇Python解析、提取url關(guān)鍵字的實例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • Python TensorFlow 2.6獲取MNIST數(shù)據(jù)的示例代碼

    Python TensorFlow 2.6獲取MNIST數(shù)據(jù)的示例代碼

    這篇文章主要介紹了Python TensorFlow 2.6獲取MNIST數(shù)據(jù)的的相關(guān)示例,文中有詳細的代碼示例供大家參考,對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-04-04
  • 基于Python的圖像閾值化分割(迭代法)

    基于Python的圖像閾值化分割(迭代法)

    這篇文章主要介紹了基于Python的圖像閾值化分割(迭代法),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • 在PyCharm搭建OpenCV-python的環(huán)境的詳細過程

    在PyCharm搭建OpenCV-python的環(huán)境的詳細過程

    這篇文章主要介紹了在PyCharm搭建OpenCV-python的環(huán)境的詳細過程,本文通過圖文并茂的形式給大家介紹搭建步驟,對PyCharm搭建OpenCV-python環(huán)境相關(guān)知識感興趣的朋友一起看看吧
    2022-05-05
  • python實現(xiàn)圖像處理之PiL依賴庫的案例應(yīng)用詳解

    python實現(xiàn)圖像處理之PiL依賴庫的案例應(yīng)用詳解

    這篇文章主要介紹了python實現(xiàn)圖像處理之PiL依賴庫的案例應(yīng)用詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • Python3 sys.argv[ ]用法詳解

    Python3 sys.argv[ ]用法詳解

    這篇文章主要介紹了Python3 sys.argv[ ]用法詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10

最新評論

禹城市| 廉江市| 光山县| 喀什市| 普定县| 双鸭山市| 庄河市| 沛县| 鹤山市| 兴和县| 凤阳县| 临洮县| 军事| 庆安县| 武冈市| 临沂市| 甘肃省| 汽车| 十堰市| 邹平县| 芜湖县| 咸宁市| 南汇区| 霍山县| 天长市| 炉霍县| 曲阜市| 清水河县| 邯郸市| 崇左市| 岢岚县| 清镇市| 尤溪县| 奈曼旗| 湖南省| 齐齐哈尔市| 阆中市| 太仓市| 商水县| 屏东县| 沽源县|