Sends a Slack notification for Gmail messages tagged with a specific label.
Installation comprises the following steps:
- Create a Slack incoming WebHook for your workspace.
- Install and configure a Google Apps script in your Apps domain.
- Set up a Gmail filter to mark the messages you want to be notified of.
- Set an installable trigger for running the notification script at specified intervals.
- Go to your Slack workspace Administration → Manage Apps section.
- Choose Custom Integrations → Incoming WebHooks.
- Create a new WebHook by clicking on Add to Slack.
- Select Slackbot as the “Post to Channel” (you can also choose some other channel, but this way only you see the notifications).
- Click on Add Incoming WebHooks Integration.
- Save the WebHook URL from the resulting page.
- (Optional) Set a custom name (for example “gmail notification” and an image for your notification messages.
- Log on your Google Apps domain.
- Go to https://script.google.com/ and create a new project.
- Your new project is unnamed. Give it a name (for example, “Ping Slack from Gmail”�) by clicking on the Unnamed Project text.
- Your project script file is open. Copy and paste the contents of
pingSlackForGmail.gs
into the editor window. - Set the Slack WebHook URL into the
webhookURL
variable and save the script. - 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).
- 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). - As filter action, check Apply the label and create a new label called
slack-notify
for the messages. - 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.
- Go back to the Google Apps editor.
- Valitse Edit → Show triggers for current project and add a new trigger.
- Set the trigger to run
notifyOfTaggedMessages
- Choose a time-driven trigger.
- 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).
- After saving, your trigger is now in use and you will be notified automatically of new Gmail messages that match your filters.