Aug-14-2018, 08:30 AM
This is the code I tried to extract only Subject and senders name.
import imaplib import email mail = imaplib.IMAP4_SSL('imap.gmail.com') mail.login('user_name','password') mail.list() mail.select('INBOX') typ, data = mail.search(None,'ALL') for i in data[0].split(): typ, data = mail.fetch(i, '(RFC822)') for response_part in data: if isinstance(response_part, tuple): msg = email.message_from_string(str(response_part[1])) varSubject = msg['subject'] varFrom = msg['from'] print('[ %s ] %s' %(varFrom, varSubject))This is the output I'm getting.
Output:[ None ] None
[ None ] None
[ None ] None
[ None ] None
[ None ] None
[ None ] None
[ None ] None
[ None ] None
Can anyone tell me what's wrong with the code?