To read a specified email through the POP3 protocol, you must first install the maillib library. Assume that I want to obtain the first URL of each email sent by Douban in a week. The Python code import poplib import maillib from datetime import datetime, timedelta www.2cto.com def email_filter (sender, body): target = "http: //" sender, body = sender [1], body. split ("\ n") if sender = "webmaster@douban.com": for line in body: if target in line: return line. strip () def read_email (email, password, host, port = 110, days = 0): conn = poplib. POP3 (host, port) # conn. set_debuglevel (1) # output debugging information conn. user (email) conn. pass _ (password) links = [] nr = conn. stat () [0] # obtain the number of mails for I in range (nr, 0,-1): server_msg, body, octets = conn. retr (I) msg = maillib. message. from_string ("\ n ". join (body) today = datetime. now (). replace (hour = 0, minute = 0, second = 0, microsecond = 0) if msg. date <today-timedelta (days = days): break www.2cto.com link = email_filter (msg. sender, msg. body) if link: links. append (link) return links if _ name _ = "_ main _": links = read_email ("me@126.com", "pass", host = "pop.126.com ", days = 7) for link in links: print link author ryan. liu