Question : Getting the date of a email using IMAP in python

Hi,

See my code..

How to I get the date and time of the email using IMAP?  What is the magic line that I should add?
e.g. datetime_mgs = ??????

I am new to IMAP so please be precise....

Thanks


Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
c = open_connection()
typ, data = c.select('INBOX')
typ, msg_ids = c.search(None, '(FROM "XXX#dfadfaf.com")') #SUBJECT "Your report contains no data"
msg_ids = msg_ids[0].split(' ')
 
####################################################################
#For each message---find the relevent data
####################################################################
for msg_fet in msg_ids:
    typ, msg_data = c.fetch(msg_fet, '(RFC822)')
    for response_part in msg_data:
        if isinstance(response_part, tuple):
            msg = email.message_from_string(response_part[1])
Open in New Window Select All

Answer : Getting the date of a email using IMAP in python

typ, datetime_mgs = c.fetch(msg_fet, '(BODY[HEADER.FIELDS (DATE)])')
Random Solutions  
 
programming4us programming4us