Python收发邮件

问题是,邮件正文可能是base64编码也可能是gb2312编码,如何始终获取正文呢
[python]
import poplib,email
try:
p=poplib.POP3(‘pop.qq.com’)
p.user(‘xx’)
p.pass_(‘xx’)
ret = p.stat()
except poplib.error_proto,e:
print "Login failed:",e
list=p.list()[1]
list.reverse()
for item in list:
number,octets = item.split(‘ ‘)
lines=p.retr(number)[1]
for piece in lines:
print piece
[/python]
发邮件:
[python]
import smtplib
try:
handle = smtplib.SMTP(‘smtp.163.com’, 25)
handle.login(‘xx@163.com’,’xx’)
msg = "To:to@qq.comrnFrom:xx@163.comrnSubject:hi rnrnhellorn"
handle.sendmail(‘xx@163.com’,’to@qq.com’, msg)
handle.close()
except Exception,e:
print e
[/python]

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据