Python收发邮件


Python #收发邮件2012-11-27 23:44
收邮件,邮件正文可能是base64编码也可能是gb2312编码,如何始终获取正文呢
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

发邮件:

import smtplib
try:
    handle = smtplib.SMTP('smtp.163.com', 25)
    handle.login('xx@163.com','xx')
    msg = "To:to@qq.com\r\nFrom:xx@163.com\r\nSubject:hi http://yige.org \r\n\r\nhello\r\n"
    handle.sendmail('xx@163.com','to@qq.com', msg)
    handle.close()
except Exception,e:
    print e

相关文章

粤ICP备11097351号-1