Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/swinton/gmail-repl

A REPL for GMail
https://github.com/swinton/gmail-repl

cli gmail gmail-api nodejs repl shell

Last synced: about 1 month ago
JSON representation

A REPL for GMail

Awesome Lists containing this project

README

        

# ๐Ÿ” `gmail-repl`

> A REPL for GMail

## Setup

Follow [the Node.js quickstart](https://developers.google.com/gmail/api/quickstart/nodejs) from theย Gmail for Developers guide, and make sure your [desktop application credentials](https://developers.google.com/gmail/api/quickstart/nodejs#authorize_credentials_for_a_desktop_application) are stored in a `credentials.json` file -- see [`credentials-example.json`](credentials.example.json) for an example.

## Usage
```shell
./repl.js
```

## Examples

### Get profile
> [`users.getProfile`](https://developers.google.com/gmail/api/reference/rest/v1/users/getProfile)

```javascript
await profile()
```

### List messages
> [`users.messages.list`](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list)

- See: [Search operators you can use with Gmail](https://support.google.com/mail/answer/7190?hl=en)

```javascript
// List all messages
await messages()

// List all from
await messages('from:[email protected]')

// List unread from sent after
await messages('from:[email protected] is:unread after:2023/05/19')
```

### Read a message
> [`users.messages.get`](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/get)

```javascript
await message('1883a5111e8ef47c')
```

### List threads
> [`users.threads.list`](https://developers.google.com/gmail/api/reference/rest/v1/users.threads/list)

- See: [Search operators you can use with Gmail](https://support.google.com/mail/answer/7190?hl=en)

```javascript
// List all threads
await threads()

// List all from
await threads('from:[email protected]')

// List unread from sent after
await threads('from:[email protected] is:unread after:2023/05/19')

```

### Read a thread
> [`users.threads.get`](https://developers.google.com/gmail/api/reference/rest/v1/users.threads/get)

```javascript
await thread('1883b361aaef86b6')
```

### Batch delete
> [`users.messages.batchDelete`](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/batchDelete)

- See: [Search operators you can use with Gmail](https://support.google.com/mail/answer/7190?hl=en)

#### Batch delete unimportant promotional messages

```javascript
await batchDeleteMessages('category:promotions -is:important -is:starred')
```

#### Batch delete messages from before 2021

```javascript
await batchDeleteMessages('before:2021/01/01')
```