5
Gmail의 IMAP 서버에서 이메일을 확인하는 python 스크립트가 있습니다. 서버에 최신 이메일이 표시됩니다. 그러나 이메일 주소는 여러 다른 계정에서 이메일을 수신하고 있습니다. 이 스크립트를 사용하여 특정 발신자에게 보내는 메시지 만 볼 수있게하려면 어떻게해야합니까? 예를 들어, "[email protected]"에게만 전송 된 모든 이메일이 나타납니다.Python - imaplib - 특정 발신자에게 메시지보기
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('[email protected]', 'password123')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.
result, data = mail.search(None, "ALL")
ids = data[0] # data is a list.
id_list = ids.split() # ids is a space separated string
latest_email_id = id_list[-1] # get the latest
result, data = mail.fetch(latest_email_id, "(RFC822)") # fetch the email body (RFC822) for the given ID
raw_email = data[0][1] # here's the body, which is raw text of the whole email
# including headers and alternate payloads
미리 감사드립니다. :)
당신이 대신 "ALL", mail.search에서(), 당신이 원하는 메시지를 검색 할 때 어떻게됩니까? – Dave