【实例简介】
【实例截图】
【核心代码】
def LoginMail(hostname, user, password):
r = imaplib.IMAP4_SSL(hostname)
r.login(user, password)
x, y = r.status('INBOX', '(MESSAGES UNSEEN)')
print(x)
print(str(y))
allmes, unseenmes = re.match(r'.*\s (\d )\s .*\s (\d )', str(y)).groups()
tomail = ('%s 有 %s 封邮件, %s 封是未读 ' % (user, allmes, unseenmes))
time_tup = time.localtime(time.time())
format_time = '%Y-%m-%d %H:%M:%S'
cur_time = time.strftime(format_time, time_tup)
print(cur_time)
with open('未读邮件.txt', 'a ') as f:
f.write( cur_time '\t' tomail '\n')
r.logout()