gmail-query-services v0.0.7
:mailbox_with_no_mail: gmail-query-services
lib to facilitate integration with gmail
Prerequisites
- 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.
Installation
npm i gmail-query-services
envs
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)
Importing
const { authorizer, message } = require('../src')
Authorizer
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()
Overview
Response body
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
Query functions
from
await message().from(email).exec()
subject
await message().subject(subject).exec()
hasAttachment
await message().from(email).hasAttachment().exec()
If you are looking for a file name
await message().from(email).hasAttachment('filename').exec()
after
await message().from(email).after(date).exec()
before
await message().from(email).before(date).exec()
Date Warning
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
read
await message().from(email).read().exec()
unread
await message().from(email).read(false).exec()
contains
await message().from(email).contains('hello').exec()