Example with Google API
Last updated
Was this helpful?
Last updated
Was this helpful?
In the previous example we used IMAP client to connect to Gmail inbox. That can be also done by using Gmail API. You can find on GitHub a by Google, which implements OAuth authorization and retrieves list of labels from user's mailbox.
The example app is surprisingly easy to set up. You just need to follow .
As you run the app first time it asks you to follow a printed URL to Google Services where you will be prompted to register the app. At the end you receive a code, which hand back to the application.
But we do not need labels, but last received email addressed to a given user name alias. Well we can modify a bit . First let's get rid of fs.readFile('credentials.json', (err, content) => ...
block. We rather get OAuth client with an asynchronous function instead of coping with callback hell:
Now implement a function that accepts and returns either raw body of the first matching the query message or nothing if no matches found:
Well, now we can use these functions from the bridge code like that: