Skip to content

nandenjin/gmail-to-slack

Repository files navigation

📧 Gmail to Slack Forwarder

GitHub Workflow Status Code Climate maintainability Codecov GitHub

What's this

Forward emails from Gmail to Slack by using Google Apps Script.

Features

  • Filter by "label" of Gmail (configurable automation by "filters")
  • Integrates with any channels in Slack by Incoming Webhooks
  • Web-based configuration UI

[!NOTE] > For users of paid plans: You can use channel email address, which is an official built-in feature of Slack.

Actual behavior of this script is very simple:

  1. Search threads with specified label from Gmail.
  2. Forward it to Slack.
  3. Reomve the label from the thread.

for each time it is called.

How to setup

1. Initialization of the package

Clone the repository and install dependencies.

# Clone repository
git clone https://github.com/nandenjin/gmail-to-slack.git
cd gmail-to-slack

# Install dependencies
yarn install

2. Create script

Create a new project of Google Apps Script (GAS) by using clasp

# If needed
npx clasp login

# Create a project
npx clasp create --rootDir src

...or setup manually with exist project.

cp .clasp.template.json  .clasp.json
{
  "scriptId": "REPLACE_WITH_YOUR_PROJECT_ID",
  "rootDir": "src"
}

3. Push and deploy

Push codes to project.

clasp push

Open GAS web editor and publish a deployment.

clasp open

Make sure the script is available only for yourself(Execute as = Me, Who has access = Only myself) or someone can get your configurations: list of your Gmail labels and Slack Webhook URL.

4. Configure with Web UI

Open the URL that be shown at deployment modal.

Select a label to use to flag emails to be forwarded, and set Slack Outcoming Webhook URL.

4. Configure trigger

Back to GAS web editor and setup time-driven trigger to function main.

All ready! Test the things by adding the label to some threads manually, and confirm that they will be forwarded to intended channel.

Contribute

If you have any trouble or question, feel free to ask at discussion of GitHub. Opening issue or submitting PRs are also welcome.