Skip to content

Gmail and slack integration to receive emails on slack

Notifications You must be signed in to change notification settings

adizhavo/slackmail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slackmail is a gmail and slack integration to receive emails in your slack channel for OSX and Linux

The system uses jq deserialise json, so before proceeding make sure to have it.

Dont forget to make the all the scripts executable with the command chmod +x <script>

Gmail API

  • Enable the API in the google developer console
  • Create credentials as a OAuth Client Id and choose Other as an application type
  • Copy and paste client_id and client_secret code in the config

the scope is already defined in the authorisation script as https://www.googleapis.com/auth/gmail.readonly

Slack app

  • Create a Slack app
  • Activate the Incoming Webhook functionality
  • Select the channel you want the app to post your emails
  • Copy and past the Webhook URL in the config

Gmail Authorization

Executing the email_authorization.bsh script will open the browser and let you pick up your gmail account. After choosing, it will give back an authrization code, copy and past it to the terminal to complete the authorisation.

If its successful, it will create a file called token.json under the resources folder. If this file is deleted another authorisation is required.

Cron job

The final step is to execute the slack_mail.bsh script to gets and unread emails form the gmail account and post them on slack. This is done by setting up a cron job.

slack_mail.bsh takes two arguments:

  • The path where the resources exists
  • The path to the jq library

The first argument is required, the second is optional if you are manually executing the script but for the cron job the path to jq is required since the cron job is called by the system that doesn’t have the same environment variable of your shell.

To get the path to the jq library execute the command type jq

To start a cron job execute the command crontab -e and put your cron job command in the file.

Mine is * * * * * /Slackmail/slack_mail.bsh /Slackmail /usr/local/bin/jq >/tmp/slackmail.log;

Improvements

  • Support multiple gmail accounts
  • Improve slack post format