Poplib을 통해받은 편지함만으로 메일을 선택하십시오
문제
Poplib을 사용하여 Gmail받은 편지함에서 이메일을 다운로드해야합니다. 불행히도받은 편지함 만 선택할 수있는 옵션이 표시되지 않으며 Poplib은 전송 된 항목의 이메일도 제공합니다.
받은 편지함에서만 이메일을 선택하려면 어떻게해야합니까?
Gmail 특정 라이브러리를 사용하고 싶지 않습니다.
해결책
POP3 has no concept of 'folders'. If gmail is showing you both 'sent' as well as 'received' mail, then you really don't have any option but to receive all that email.
Perhaps you would be better off using IMAP4 instead of POP3. Python has libraries that will work with gmail's IMAP4 server.
다른 팁
I assume you have enabled POP3/IMAP access to your GMail account.
This is sample code:
import imaplib
conn= imaplib.IMAP4_SSL('imap.googlemail.com')
conn.login('yourusername', 'yourpassword')
code, dummy= conn.select('INBOX')
if code != 'OK':
raise RuntimeError, "Failed to select inbox"
code, data= self.conn.search(None, ALL)
if code == 'OK':
msgid_list= data[0].split()
else:
raise RuntimeError, "Failed to get message IDs"
for msgid in msgid_list:
code, data= conn.fetch(msgid, '(RFC822)')
# you can also use '(RFC822.HEADER)' only for headers
if code == 'OK':
pass # your code here
else:
raise RuntimeError, "could not retrieve msgid %r" % msgid
conn.close()
conn.logout()
or something like this.
This Java code would suggest that you can select a particular "folder" to download, even when using POP3. Again, this is using Java, not Python so YMMV.
제휴하지 않습니다 StackOverflow