How to check GMail inbox from command line

First of all we have to create an application password here.
Then, create bash script like this one:

# crontab example line
# */4 * * * * /home/username/ 

export DISPLAY=:0


/usr/bin/curl -u $username:$password --silent "" | \
  grep -oPm1 "(?<=<title>)[^<]+" | sed '1d' | \
  while read line; do 
    /usr/bin/notify-send -i xfce-newmail "You've got new mail!" "$line" -t 5000
After that, you can add this script to your cron using crontab -e. As you see, notify-send is used here to display system notification (XFCE, in my case) for each new mail received, in your case you can change that in the way you like.
Original note here.