Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

How to read specific email in python

$
0
0

I have the following code:

import imaplib
import email





imap = imaplib.IMAP4_SSL('imap.naver.com')
id = 'abc@naver.com'
pw = '123'
imap.login(id, pw)


imap.select('inbox')
status, data = imap.uid('search', None, '(HEADER FROM "abd@gmail.com")')

if status == 'OK':
    if data[0]:
        mid = data[0].split()[0]
        print('mail id', mid)
        print(imap.fetch(mid, '(UID BODY[HEADER.FIELDS (HEADER FROM)])'))

It raised FETCH command error: BAD [b'Error in IMAP command FETCH: Invalid messageset']

print (status, data)

It returned

OK [b'3769 3838 3845 3896 3907 3916 3961 3978 3989 3991 3993 4002 4017 4059 4069 4607 4608 4612 4613']

what is wrong in my code?

How can I read specific email?


Viewing all articles
Browse latest Browse all 29748

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>