python之mail簡單使用(html)

來源:互聯網
上載者:User

標籤:使用者名稱   圖片   伺服器   python   import   

#!/usr/bin/env python# -*- coding: UTF-8 -*-#該郵件功能只是發送基本的常值內容,不帶任何附件與圖片,發送格式是以html發送的import smtplib  from email.mime.text import MIMEText  mailto_list=[‘[email protected]‘,‘[email protected]‘] mail_host="smtp.163.com"  #設定伺服器mail_user="[email protected]"    #使用者名稱mail_pass="XXXXXX"   #口令 mail_postfix="163.com"  #寄件匣的尾碼#HTML程式碼片段h = """<table width="800" border="0" cellspacing="0" cellpaddind="4">    <tr>        <td bgcolor="#CECFAD" height="20" style="font-size:14px">*假官網資料<a href="    </tr>        <tr>    <td bgcolor="#EFEBDE" height="100" style="font-size:13px">1)日訪問量:<font color=red>152433</font><br> 2)狀態代碼資訊<br>&nbsp;&nbsp;500:105 404:3264 503:214</br>3)訪問瀏覽器資訊<br>&nbsp;&nbsp;IE:50% firefox:10% chrome:30% other:10%</br>    </td>  </tr></table>"""def send_mail(to_list,sub,content):      me="163"+"<"+mail_user+"@"+mail_postfix+">"      msg = MIMEText(content,‘html‘,‘utf-8‘)      #固定格式    msg[‘Subject‘] = sub   #主題    msg[‘From‘] = me       #寄件者    msg[‘To‘] = ";".join(to_list) #收件者清單     try:          server = smtplib.SMTP()          server.connect(mail_host)  #建立串連        server.login(mail_user,mail_pass)   #登入郵箱        server.sendmail(me, to_list, msg.as_string())#發送郵箱        server.close()  #關閉串連        return True      except Exception, e:  #發送異常後,將異常狀態列印出來        print str(e)          return False  if __name__ == ‘__main__‘:     #真正執行的地方!     if send_mail(mailto_list,"hello",h):  #參數:收件者清單,主題,內容        print "發送成功"      else:          print "發送失敗"


本文出自 “嚮往|那一片天空” 部落格,請務必保留此出處http://fiyaster.blog.51cto.com/6668127/1676250

python之mail簡單使用(html)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.