There are two solutions to this:
- Use the Gmail client authentication via an interactive browser login
- Use a totally background authentication mechanism, but this requires some fiddly user setup in the Google API page to create an endpoint for the connection.
The second option requires you the user to set-up some API access credentials in the Google API under your user account. This is non-trivial, and whilst I managed to get it working at one point, I have failed on a subsequent attempt!
It looks to me like option 1 is the least worst option?