I have come through solutions to extract useful information from selected received emails in Gmail mailbox.
Aim in this example is to fetch all mails sent from a newsletter providing monthly prices for petroleum. You can freely subscribe to such a newsletter on EIA website. All such newsletter arrive in same folder in my gmail mailbox, and begin with “$”.
Content for emails is like that

and my objective is to write a script that fetch the 10 last such emails (last 10 months) and plot petroleum prices for the different US regions with respect to time.
Python
emaillibrary will help.This directory is where you will save attachments
Your script then asks user (or yourself) for account features
Connect then to the gmail imap server and login
Select one folder, you could use the whole INBOX instead
One should use
m.list()to get all the mailboxes. Search for all emails coming from specified sender andselect the mail ids:
I want the last emails, so that I am using
items[::-1]I want only the ones beginning with
$I want only the N=100 last messages
Use regular expressions to fetch relevant information
Plot all these curves with US prices
Some related interesting topics are here
Get only new emails
Fetch mail body
Forward emails with attachment
Fetch body emails in gmail
Results are here for three areas only