我正在使用 ImapClient。我无法阅读传入消息的内容。如何阅读邮件内容、时间和发件人?
from imapclient import IMAPClient
import email
HOST = 'imap.gmail.com'
USERNAME = 'username'
PASSWORD = 'password'
server = IMAPClient(HOST)
server.login(USERNAME, PASSWORD)
server.select_folder('INBOX')
# Start IDLE mode
server.idle()
print("Connection is now in IDLE mode, send yourself an email or quit with ^c")
while True:
try:
# Wait for up to 30 seconds for an IDLE response
responses = server.idle_check(timeout=10)
print("Server sent:", responses if responses else "nothing")
except KeyboardInterrupt:
break
server.idle_done()
print("\nIDLE mode done")
server.logout()