亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

一、文件形式的郵件

復(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)文章

  • Pyecharts可視化圖片渲染的方法詳解

    Pyecharts可視化圖片渲染的方法詳解

    使用 pyecharts 渲染成圖片一直是開(kāi)發(fā)者比較關(guān)心的功能,pyecharts提供了selenium、phantomjs和pyppeteer 三種方式。本文將具體介紹一下這三種方式的使用,需要的可以參考一下
    2022-02-02
  • Sklearn多種算法實(shí)現(xiàn)人臉補(bǔ)全的項(xiàng)目實(shí)踐

    Sklearn多種算法實(shí)現(xiàn)人臉補(bǔ)全的項(xiàng)目實(shí)踐

    本文主要介紹了Sklearn多種算法實(shí)現(xiàn)人臉補(bǔ)全的項(xiàng)目實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • python 獲取字符串MD5值方法

    python 獲取字符串MD5值方法

    今天小編就為大家分享一篇python 獲取字符串MD5值方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Python+numpy實(shí)現(xiàn)一個(gè)蜘蛛紙牌游戲

    Python+numpy實(shí)現(xiàn)一個(gè)蜘蛛紙牌游戲

    蜘蛛紙牌大家玩過(guò)沒(méi)有?之前的電腦上自帶的游戲,用他來(lái)摸魚(yú)過(guò)的舉個(gè)手。但是現(xiàn)在的電腦上已經(jīng)沒(méi)有蜘蛛紙牌了。所以本文就來(lái)用Python做一個(gè)吧,需要的可以參考一下
    2022-12-12
  • python利用文件時(shí)間批量重命名照片和視頻

    python利用文件時(shí)間批量重命名照片和視頻

    這篇文章主要為大家詳細(xì)介紹了python利用文件時(shí)間批量重命名照片和視頻,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-02-02
  • Python?3行代碼提取音樂(lè)高潮部分

    Python?3行代碼提取音樂(lè)高潮部分

    這篇文章主要介紹了利用Python代碼提取音樂(lè)高潮部分,文章圍毆繞Python代碼的相關(guān)詳情展開(kāi)提取音樂(lè)的內(nèi)容,需要的小伙伴可以參考一下
    2022-01-01
  • Python異步與定時(shí)任務(wù)提高程序并發(fā)性和定時(shí)執(zhí)行效率

    Python異步與定時(shí)任務(wù)提高程序并發(fā)性和定時(shí)執(zhí)行效率

    Python異步與定時(shí)任務(wù)是Python編程中常用的兩種技術(shù),異步任務(wù)可用于高效處理I/O密集型任務(wù),提高程序并發(fā)性;定時(shí)任務(wù)可用于定時(shí)執(zhí)行計(jì)劃任務(wù),提高程序的執(zhí)行效率。這兩種技術(shù)的應(yīng)用有助于提升Python程序的性能和效率
    2023-05-05
  • 淺談python之自動(dòng)化運(yùn)維(Paramiko)

    淺談python之自動(dòng)化運(yùn)維(Paramiko)

    這篇文章主要介紹了淺談python之自動(dòng)化運(yùn)維(Paramiko),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • Python內(nèi)置函數(shù) next的具體使用方法

    Python內(nèi)置函數(shù) next的具體使用方法

    這篇文章主要介紹了Python內(nèi)置函數(shù) next的具體使用方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • python socket 超時(shí)設(shè)置 errno 10054

    python socket 超時(shí)設(shè)置 errno 10054

    這篇文章主要介紹了python 遠(yuǎn)程主機(jī)強(qiáng)迫關(guān)閉了一個(gè)現(xiàn)有的連接 socket 超時(shí)設(shè)置 errno 10054 ,需要的朋友可以參考下
    2014-07-07

最新評(píng)論