python发邮件html格式入门实例

发布时间:2020-12-13编辑:脚本学堂
有关python发邮件的一段代码,使用smtplib模块与MIMEMultipart、MIMEText模块发送邮件的例子,需要的朋友参考下。

例子,python 发送邮件代码
 

复制代码 代码示例:

#!/usr/bin/env python
#

import datetime 
import mysqldb/ target=_blank class=infotextkey>MySQLdb 
import sys 
import smtplib 
from email.mime.multipart import MIMEMultipart 
from email.mime.text import MIMEText 
__author__ = 'ninghao' 
def send_mail(): 
        me = "mactonish@163.com" 
        you = "ninghao@sohu-inc.com" 
        msg = MIMEMultipart('alternative') 
        msg['Subject'] = "dean , its what u want " 
        msg['From'] = me 
        msg['To'] = you 
        text = "dean , the thing what u want , I send to you !!!! 2324211232" 
        html = """ 
        <html> 
          <head></head> 
          <body> 
            <p>Hi!<br> 
               news , mike is dead ! 
            </p> 
          </body> 
        </html> 
        """ 
        part1 = MIMEText(text, 'plain') 
        part2 = MIMEText(html, 'html') 
        msg.attach(part1) 
        msg.attach(part2) 
        s = smtplib.SMTP() 
        s.connect('smtp.163.com',25) 
        s.login("mactonish","mima") 
        s.sendmail(me, you, msg.as_string()) 
        s.close() 
if __name__ == "__main__": 
    send_mail() 
    print "haha" 

附,以下代码提升进程优先级,没看太懂,懂的朋友分享下你的观点哦。
 

复制代码 代码示例:

#!/usr/bin/python -u  
import os 
import sys 
import subprocess 
import time

while True: 
        stdout = subprocess.Popen("top -bn 1",shell=True,stdout = subprocess.PIPE) 
        print stdout.communicate()[0] 
        time.sleep(15) 


推荐阅读:python发送邮件专题教程