import imaplib
import email
M = imaplib.IMAP4_SSL("imap.sina.com")
print(M)
try:
    try:
        M.login('test@sina.com', '123456')
        print('登录成功')
    except Exception as e:
        print('login error: %s' % e)
        M.close()
    else:
        M.select()

        typ, data = M.search(None, 'ALL')
        print(len(data))
        for num in data[0].split():
            try:
                typ, data1 = M.fetch(num, '(RFC822)')
                msg = email.message_from_string(data1[0][1].decode('utf-8'))
                print(msg)
                print(msg["Date"])
            except Exception as e:
                print('got msg error: %s' % e)
        M.close()
        M.logout()
except Exception as e:
    print('imap error: %s' % e)
    M.close()

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-26
  • 2021-08-27
  • 2021-10-10
  • 2022-12-23
猜你喜欢
  • 2021-10-28
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案