- Node.js
- A Google account with Gmail enabled
In resulting dialog click DOWNLOAD CLIENT CONFIGURATION and save the file credentials.json to app config directory.
npm i gmail-query-services
env.TOKEN_PATH => the path of the gmail token env.CREDENTIALS_PATH => the path of the gmail credentials env.TIMEOUT => timeout for Google apis to respond. (default => 5 seconds)
const { authorizer, message } = require('../src')
In the first time, you need run the authorizer first, to generate the token file. Run authorizer, get the uri that service return in console, put in you browser, get the code retunr by gmail. Put de code in console, press enter. Should apear a message, "Token stored to...".
That's all.
const { authorizer } = require('../src')
authorizer.exec()
If successful, the response body contains data with the same structure on the gmail documentation.
But in the Part body, we add the attachment, if the part has a attachment. The attachment structure is the same on the gmail documentation
await message().from(email).exec()
await message().subject(subject).exec()
await message().from(email).hasAttachment().exec()
If you are looking for a file name
await message().from(email).hasAttachment('filename').exec()
await message().from(email).after(date).exec()
await message().from(email).before(date).exec()
All dates used in the search query are interpreted as midnight on that date in the PST timezone. To specify accurate dates for other timezones pass the value in seconds instead:
?q=in:sent after:1388552400 before:1391230800
await message().from(email).read().exec()
await message().from(email).read(false).exec()
await message().from(email).contains('hello').exec()