Skip to content

Instantly share code, notes, and snippets.

Last active September 6, 2017 22:04
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import hashlib
import requests
from flask import Flask, request
SLACK_CHANNEL = '#general'
SLACK_TOKEN = '********'
app = Flask(__name__)
@app.route('/mail', methods=['POST'])
def mail():
text = request.form.get('subject', '[unknown]')
sender = request.form.get('from', request.form.get('sender', '[unknown]'))
if ' <' in sender:
sender = sender.split(' <')[0]
sender_hash = hashlib.sha1(sender).hexdigest()
avatar = '' % sender_hash
'channel': SLACK_CHANNEL,
'icon_url': avatar,
'parse': 'full',
'text': text,
'token': SLACK_TOKEN,
'username': sender,
return 'OK'
if __name__ == '__main__':'', port=8003)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment