Receive gmail messages on the backend

I’m looking for a plugin that will let me retrieve new gmail messages and save them to the database even while my user is away or not logged in.

Is there a plugin that can let me do that? The gmail plugins I’ve seen only retrieve emails client side.

Use Gmail API directly

Can you please point me to a tutorial that would help me do that?

Not a tutorial but documentation
You need to have oAuth setup and manage session tokens too, also need to register your application first