If your team works on a Slack workspace, and the team has to maintain one, or a bunch of different email ids and wish to be notified of every email instantly on Slack; there is a hack for you and an alternative to Send emails to Slack which work only with Free, Standard, Plus, and Enterprise Grid plans.
After setting up your Slackbot chat as a forward emailing address of your email account (Steps explained below)
this bot watches for messages in the Slackbot chat and whenever a message arrives with an attached email, it forwards it to a channel as a message.
- Setup a
forwarding email
. If you send any email to this address, it will appear as a file in yourDirect messages
channel with Slackbot. - Add this address as a forwarding address of your email account. (For Gmail find forwarding options from Gmail settings).
- Use Slack API to get notified about this.
- Use Slack API to post the email on a channel you want to.
- Add your Slack app config in the server.
-
From Slack, navigate to:
Preferences
(top right corner icon)Messages & media
Bring emails into Slack
. It will generate an email address for you. Any email sent to this address will appear in yourDirect messages
with Slackbot.
-
Go to the email provider (like Gmail) from where you want to forward the messages to Slack. In the forwarding options, put the email generated by Slack to forward email to.
- In case of Gmail, you will have to provide a verification token which is sent to your Slackbot.
-
Go to api.slack.com/apps
- Create a new Slack App named:
Gmail Bot
or something elseOutlook Bot
- Navigate to the app dashboard and find
Event Subscriptions
in the sidebar- In
Request URL
, add your web server script urlhttps://domain.tld/email-to-slack.php
- Subscribe to
message.im
inSubscribe to events on behalf of users
- In
- Create a new Slack App named:
-
In the sidebar, go to
OAuth & Permissions
- In
Scopes
, partBot Token Scopes
add these OAuth Scope:files:read
im:history
incoming-webhook
- Install your app to your Workspace
- In
-
In your server, add environment variables config, which is detailed in next part (example):
APP_ID=A12ED963ZQS INCOMING_WEBHOOK_URL=https://hooks.slack.com/services/T12DRSFGE/C02EV6KLCCY/neWIoLN0nXQ0obVgHlxXmYgc TEAM_ID=T12DRSFGE USlackbot_CHANNEL=D050CBER9 VERIFICATION_TOKEN=ZZHla9Kj8l4L28PceIoDB3IX
Refer to SLACK API FAQ for more help.
A bit more?
- In
Basic Information
, you can changeDisplay Information
to get beautiful notifications
- Set these environment variables in your server:
Config Variable | Description |
---|---|
APP_ID |
You get this when you create the app |
INCOMING_WEBHOOK_URL |
You get this when you install the app on one channel |
TEAM_ID |
ID of your slack workspace. See this |
USLACKBOT_CHANNEL |
The ID of the direct messaging channel between you and @slackbot |
VERIFICATION_TOKEN |
You get this when you create the app |
Note that the Slack IDs (for a channel, users, files) are alphanumeric uppercase string of 9 characters.
Notes:
- Slack creates a beautiful file for an email. But I could not find way to change file permissions which is shared privately with just the user. Hence, I have to customize and post the email. If there is a way to change file permissions from private to be shared in a team, that would be easy and the best way.
- A Google Script version gmailToSlack.js
This project is licensed under the MIT License - see the LICENSE details.
This was designed with the inspiration from this fine folks:
- a Python version of email-to-slack from KOSS-Kharagpur Open Source Society