日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python實現的發郵件功能示例

系統 1812 0

本文實例講述了python實現的發郵件功能。分享給大家供大家參考,具體如下:

一 簡介

本應用實現給網易郵箱發送郵件

二 代碼

            
import smtplib
import tkinter
class Window:
  def __init__(self,root):
    label1 = tkinter.Label(root,text='SMTP')
    label2 = tkinter.Label(root,text='Port')
    label3 = tkinter.Label(root,text='用戶名')
    label4 = tkinter.Label(root,text='密碼')
    label5 = tkinter.Label(root,text='收件人')
    label6 = tkinter.Label(root,text='主題')
    label7 = tkinter.Label(root,text='發件人')
    label1.place(x=5,y=5)
    label2.place(x=5,y=30)
    label3.place(x=5,y=55)
    label4.place(x=5,y=80)
    label5.place(x=5,y=105)
    label6.place(x=5,y=130)
    label7.place(x=5,y=155)
    self.entryPop = tkinter.Entry(root)
    self.entryPort = tkinter.Entry(root)
    self.entryUser = tkinter.Entry(root)
    self.entryPass = tkinter.Entry(root,show = '*')
    self.entryTo = tkinter.Entry(root)
    self.entrySub = tkinter.Entry(root)
    self.entryFrom = tkinter.Entry(root)
    self.entryPort.insert(tkinter.END,'25')
    self.entryPop.place(x=50,y=5)
    self.entryPort.place(x=50,y=30)
    self.entryUser.place(x=50,y=55)
    self.entryPass.place(x=50,y=80)
    self.entryTo.place(x=50,y=105)
    self.entrySub.place(x=50,y=130)
    self.entryFrom.place(x=50,y=155)
    self.get = tkinter.Button(root,text='發送郵件',command = self.Get)
    self.get.place(x=60,y=180)
    self.text=tkinter.Text(root)
    self.text.place(y=220)
  def Get(self):
    try:
      host = self.entryPop.get()
      port =int(self.entryPort.get())
      user = self.entryUser.get()
      pw = self.entryPass.get()
      fromaddr = self.entryFrom.get()
      toaddr=self.entryTo.get()
      subject=self.entrySub.get()
      text = self.text.get(1.0,tkinter.END)
      msg =("From:%s\nTo:%s\nSubject:%s\n\n"
         % (fromaddr,toaddr,subject))
      msg = msg+text
      smtp=smtplib.SMTP(host,port)
      smtp.set_debuglevel(1)
      smtp.login(user,pw)
      smtp.sendmail(fromaddr,toaddr,msg)
      smtp.quit()
    except Exception as e:
      self.text.insert(tkinter.END,'發送錯誤\n')
root =tkinter.Tk()
window=Window(root)
root.minsize(600,400)
root.mainloop()


          

三 運行結果

python實現的發郵件功能示例_第1張圖片

更多關于Python相關內容可查看本站專題:《Python Socket編程技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總》

希望本文所述對大家Python程序設計有所幫助。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 吴江市| 汪清县| 海原县| 乳山市| 怀集县| 师宗县| 南漳县| 东平县| 米林县| 眉山市| 景德镇市| 云和县| 罗江县| 呼和浩特市| 阳原县| 长兴县| 高青县| 舞阳县| 东平县| 西青区| 定州市| 韩城市| 驻马店市| 沛县| 金溪县| 遵义县| 遵义市| 宜川县| 和硕县| 博爱县| 法库县| 吉林市| 娄底市| 松阳县| 西青区| 自贡市| 昆山市| 镇雄县| 旅游| 清丰县| 河源市|