##!/usr/bin/env python
# -*- coding: utf8 -*-
#此脚本为发送此邮件的脚本程序
#导入smtplib和MIMEText
import os,smtplib,mimetypes
from email.mime.text import MIMEText
from email.mime.p_w_picpath import MIMEImage
from email.mime.multipart import MIMEMultipart
#############
#要发给谁,这里指定邮箱
mailto_list1=["xxxxx@xxx.com"]
#####################
#设置服务器,用户名、口令以及邮箱的后缀
mail_host="smtp.xxx.com"
mail_user="xxxxx"
mail_pass="xxxxx"
mail_postfix="xxx.com"
######################
def send_mail(to_list1,sub,content,filename=None):
    '''
    to_list:发给谁
    sub:主题
    content:内容
    send_mail("aaa@126.com","sub","content")
    '''
    me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
#    msg = MIMEText(content,_charset='utf-8')
    msg=MIMEMultipart()
    msg.attach(MIMEText(content,_charset='utf-8'))
    msg['Subject'] = sub
    msg['From'] = me
    msg['To'] = ";".join(to_list1)
    if filename != None and os.path.exists(filename):
        ctype, encoding = mimetypes.guess_type(filename)
        if ctype is None or encoding is not None:
            ctype = "application/octet-stream"
            maintype, subtype = ctype.split("/", 1)
            p_w_upload = MIMEImage((lambda f: (f.read(), f.close()))(open(filename, "rb"))[0], _subtype = subtype)
            p_w_upload.add_header("Content-Disposition", "p_w_upload", filename = filename)
            msg.attach(p_w_upload)  
    try:
        s = smtplib.SMTP()
        s.connect(mail_host)
        s.login(mail_user,mail_pass)
        s.sendmail(me, to_list1, msg.as_string())
        s.close()
        return True
    except Exception, e:
        print str(e)
        return False
if __name__ == '__main__':
#    cwd="cat /root/python/20121114/mail.py"
#    p=os.popen(cwd).read()
    if send_mail(mailto_list1,"python测试邮件","测试邮件",r"e:\p_w_upload.rar"):
        print "发送成功"
    else:
        print "发送失败" 
 

参考:http://flykite.blog.51cto.com/4721239/849899