Chinaunix首页 | 论坛 | 博客
  • 博客访问: 202466
  • 博文数量: 32
  • 博客积分: 3319
  • 博客等级: 中校
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-26 21:40
文章分类

全部博文(32)

文章存档

2010年(31)

2009年(1)

分类: Python/Ruby

2010-04-22 15:54:54

#!/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


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

jian_g_2011-08-17 16:24:15

试了,把s.login注释掉就能发,不错,转了