Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3285260
  • 博文数量: 515
  • 博客积分: 5116
  • 博客等级: 大校
  • 技术积分: 4137
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-30 11:24
个人简介

黑马王子就是我! 技术认证:系统分析师,网络规划设计师,网络工程师,信息系统监理师,系统集成项目管理师,初级程序员,MCSE,MCDBA,CCNA 目前主攻虚拟化技术,VPN,系统架构,集群和高可用性等。

文章分类

全部博文(515)

文章存档

2023年(11)

2022年(17)

2021年(19)

2020年(28)

2019年(42)

2018年(53)

2017年(41)

2016年(33)

2015年(43)

2014年(25)

2013年(13)

2011年(6)

2010年(28)

2009年(47)

2008年(55)

2007年(26)

2006年(28)

分类: 系统运维

2017-06-16 13:46:18

#!/usr/bin/env python
# -*- coding=utf-8 -*-

import smtplib
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

sender = "pywugw@163.com"
rcpt   = "pywugw@163.com"
msg    = MIMEMultipart('alternatvie')
msg['Subject'] = Header("测试发信","utf-8")                      #组装信头
msg['From']    = r"%s " % Header("小吴","utf-8") #使用国际化编码
msg['To']      = rcpt

html = open('html.tpl').read()                                   #读取HTML模板
html_part = MIMEText(html,'html')                                #实例化为html部分
html_part.set_charset('utf-8')                                   #设置编码
msg.attach(html_part)                                            #绑定到message里

try:
    s = smtplib.SMTP('smtp.163.com')                             #登录SMTP服务器,发信
    s.login('pywugw','*******')
    s.sendmail(sender,rcpt,msg.as_string())
except Exception,e:
    print e

阅读(1179) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~