I want to only print the sender name and message of a received gmail in Python. I tried the code given below. Please help me with that.
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('raskarakash2017@gmail.com', '02426236032')
mail.list()
mail.select('inbox')
typ, data = mail.search(None, 'ALL')
for num in data[0].split():
typ, data = mail.fetch(num, '(RFC822)')
print ('Message %s\n%s\n' % (num, data[0][1]))
mail.close()
mail.logout()
This code prints the whole information of the gmail, but I don't need that.