/gmail-to-slack

Sends a Slack notification for Gmail messages tagged with a specific label.

Primary LanguageJavaScript

gmail-to-slack

Sends a Slack notification for Gmail messages tagged with a specific label.

Installation

Installation comprises the following steps:

  1. Create a Slack incoming WebHook for your workspace.
  2. Install and configure a Google Apps script in your Apps domain.
  3. Set up a Gmail filter to mark the messages you want to be notified of.
  4. Set an installable trigger for running the notification script at specified intervals.

Slack WebHook

  1. Go to your Slack workspace Administration → Manage Apps section.
  2. Choose Custom Integrations → Incoming WebHooks.
  3. Create a new WebHook by clicking on Add to Slack.
  4. Select Slackbot as the “Post to Channel” (you can also choose some other channel, but this way only you see the notifications).
  5. Click on Add Incoming WebHooks Integration.
  6. Save the WebHook URL from the resulting page.
  7. (Optional) Set a custom name (for example “gmail notification” and an image for your notification messages.

Google Apps script

  1. Log on your Google Apps domain.
  2. Go to https://script.google.com/ and create a new project.
  3. Your new project is unnamed. Give it a name (for example, “Ping Slack from Gmail”�) by clicking on the Unnamed Project text.
  4. Your project script file is open. Copy and paste the contents of pingSlackForGmail.gs into the editor window.
  5. Set the Slack WebHook URL into the webhookURL variable and save the script.
  6. You can test the script by selecting the function notifyOfTaggedMessages in the choose action list at the top of the editor and clicking on the Run icon ⮀ (nothing should happen yet but there should be no error messages).

Gmail Filter

  1. Create a filter in Gmail for the messages you want to match (for example, by opening a thread and selecting Filter messages like this in the action menu).
  2. As filter action, check Apply the label and create a new label called slack-notify for the messages.
  3. Add the filter to an unread message. You can now go back to the script editor and run the script again. You should get a Slackbot notification.

You can create several filters for different messages, as long as they all set the same label.

Function trigger

  1. Go back to the Google Apps editor.
  2. Valitse Edit → Show triggers for current project and add a new trigger.
  3. Set the trigger to run notifyOfTaggedMessages
  4. Choose a time-driven trigger.
  5. Select and configure the type of trigger according to how often you want to be notified (for example, a minute trigger with 5-minute intervals).
  6. After saving, your trigger is now in use and you will be notified automatically of new Gmail messages that match your filters.