Hi Community! Thanks to the hard work of @decarteret I’m very happy to announce our brand new gmail adaptor!
The gmail adaptor makes it easy to fetch contents (including attachments) from a gmail inbox.
getContentsFromMessages({ query: 'in:inbox newer_than:2d' });
The results will be efficiently streamed down from the server and returned to state.data
.
By default the adaptor will use the account associated with your access token. But you can specify a different inbox with the email
option.
We’ve also got a great guide on how to get an oauth access token for local development: gmail developer readme | OpenFn/docs
If you’re interested in attachments, you can specify specific files (including file within archives) by requesting specific contents:
getContentsFromMessages(
{
query: 'after:15/01/2025',
contents: [
'subject',
{ type: 'file', name: 'metadata', file: 'report.txt'}
]
}
)
The final thing to note here is that the adaptor will returrn ids to state.processedIds
, which tells you which emails were processed in the request. If you pass processedIds on options to the next query, those items will be ignored. This helps duplicating work when running overlapping queries, since the minimum granularity of a gmail filter is one day (Ie, you can ask for emails from a given day, but not over a given time period)
Check out the docs and start hacking today, and let us know how you get on!
Huge thanks again to @decarteret for making this happen.