As part of a wider use case involving OIC, ODA and OCI AI Services, I need to be able to get emails. For that I will try out the OIC Google Gmail Adapter.
All about it here.
Pre-Requisites
On the Google side we need to configure a couple of things.
Under your google account go to https://console.developers.google.com/
Choose an existing project or create a new one. Under the option Library, search for Gmail API.
Add your callback URL
Create a connection
Pick up the Gmail Adapter from the list and provide a Client ID, Client Secret, and the Scope.
Once that is done Provide Consent, which will finalize the connection. Make sure your user is added in the Gmail OAuth consent list.
This is the list of available scopes:
https://mail.google.com/
https://www.googleapis.com/auth/gmail.compose
https://www.googleapis.com/auth/gmail.metadata
https://www.googleapis.com/auth/gmail.labels
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.send
Available Operations:
- Get Thread
- Trash Thread
- List Messages
- Get Message
- Get Message Attachment
- Send Message
- List Drafts
- Create Draft
- Get Draft
- Delete Draft
- Send Draft
- List Labels
- Create Label
- Delete Label
Create an Integration
For this exercise I will simply read the last email. For that we need to call ListMessages, which will retrieve a list of email ids (based on our query parameters) and then with the method GetMessage, we can ready a specific email.
The Integration will be an AppDriven one with a REST trigger that takes no parameters and returns the email body in the response.
Configure Gmail Connection
I will choose 3 query parameters.
Everything will be hardcoded – it’s the fast way 🙂
maxResults: 1
includeSpamTrash: false
q: from:” danielxxxx@oracle.com”
The above says that I want 1 message back, from the email “danielxxxx@oracle.com:
Add another Gmail Connection – Get Message
Ideally one would get a list of messages and then perform a For-Each and loop over all of those email ids. In this case there is only one id returned, so no need for a loop. We pass that id along to the next method (GetMessage)
This is how the integration looks like.
The last mapping is the Map to GetLastEmail
Test
The test confirms it all, and returns the last email send by my Oracle’s email to my Gmail account!