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:
#!/bin/bash

# crontab example line
# */4 * * * * /home/username/check-gmail.sh 

export DISPLAY=:0

username="your-email@gmail.com"
password="your-app-password"

/usr/bin/curl -u $username:$password --silent "https://mail.google.com/mail/feed/atom" | \
  grep -oPm1 "(?<=<title>)[^<]+" | sed '1d' | \
  while read line; do 
    /usr/bin/notify-send -i xfce-newmail "You've got new mail!" "$line" -t 5000
  done
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.