python email

本网站用的阿里云ECS,推荐大家用。自己搞个学习研究也不错

发送

# -*- coding:utf-8 -*-

import smtplib
try:
   host = “smtp.163.com”
   port = 25
   user = “tvkl”
   pw = “xxx”
   fromadd = “”
   to = “”
   sub = “123”
   msg = (“From: %s\nTo: %s\nsubject: %s\n\n”\
      % (fromadd,to,sub))
   text = “1”
   msg = msg + text
   smtp = smtplib.SMTP(host,port)
   smtp.set_debuglevel(1)
   smtp.login(user,pw)
   smtp.sendmail(fromadd,to,msg)
   smtp.quit()
except:
   print “错误”

收取

#/usr/bin/env python
import sys,os,poplib

def main():
    SERVER = “pop3.163.com”
    USER = “tvkl”
    PASSWORD=”XXXX”
    server = poplib.POP3(SERVER)
    server.set_debuglevel(1)
    server.user(USER)
    server.pass_(PASSWORD)
    resp,items,octets = server.list()

    for item in items:
        id,size = item.split(” “)
        resp,text,octets = server.retr(id)
        print resp,text,octets
        print “—————–mail No.%d—————–“
        print text
    server.quit()
if __name__ == “__main__”:
    main()

未经允许不得转载:演道网 » python email

赞 (0)
分享到:更多 ()

评论 0

评论前必须登录!

登陆 注册