Sadly, we’re still forced to use email to interact with some services that haven’t added a hook for Slack. These include some monitoring services, or just when we want a “read-only” address for people to send us updates.
The pain point I was feeling recently was with the Luigi package, which makes building data pipelines a snap. We use it extensively to build the data that backs the openfda API. Since some build steps can take several hours, it’s nice to start up a pipeline and go off to lunch (or to sleep). But when there’s a failure we want to know about it: Luigi conveniently supports email notifications for this task, but there’s no way to add a webhook.
Now the reasonable thing to do would be to just add support for a webhook notification to Luigi and send them a PR to get it merged. But then we’d still be stuck with email for all of our other services. So instead, I thought why not just proxy email to Slack directly? I know absolute nothing about SMTP or MX records, so how hard can it be? But if I made such a service, we could use it for any service that supported email notifications. (My guess is that Slack will add support for such notifications like… 3 minutes after I post this, but anyway it will be useful until then).
With that in mind, I whipped up slackmail: a SMTP server that forwards messages to Slack. To make this super-extra-convenient, there’s 2 servers: one you can use locally for testing and another one that supports adding and removing hooks dynamically. To avoid getting spammed, you can specify an authorization token which must be present in the incoming mail for it to be forwarded. The code illustrates my almost perverse lack of knowledge about SMTP, but nonetheless appears to work.
If you don’t want to run your own server, feel free to play with my example server. To register a new hook, email [email protected]. Here’s an example using the `mail` command line client:
mail -s 'Add me, yo.' [email protected]' <<HERE target_email: [email protected] webhook_url: https://hooks.slack.com/services/abc/def/awdalwidajwm authorization_token: you can't guess me HERE
To remove a hook, just email [email protected] with the same content. Once you’ve registered a hook, any emails to [email protected]` will be forwarded to your webhook. Feel free to email me at [email protected] to say hi!
(You can also email [email protected] if you like building interesting tools and helping make healthcare better!)