Saturday, January 14, 2017

Microsoft Teams: Enabling emails into a Team Channel

Today I had a bit of a look at Microsoft Teams. For some time I've been using Slack for our internal communications, but I like to look at new stuff when it comes out.

One of the mainstays of our Slack utilisation is email notifications. Whether it be for new support ticket notifications, automated warnings or whatever, having a Slack integration for emails has always been really handy.

Teams uses connectors in channels to enable various functionality. But interestingly they do not have a connector which enables receipt & display of an email to a channel. Discussions on this on the Microsoft Tech Community started to get along the lines of "this is not possible/why are you trying to do that?" which I wasn't really happy about as I think if the product is really intended to compete with Slack/Hipchat etc. then it should be bringing all the tools people might want. Am I alone in thinking that?

Anyhow... this led me to get looking around to see if there was another way of getting emails into Teams, and sure enough there is. Stefan Strangers post on Microsoft Flow was a good starting point:

From here I looked further to really accomplish what was needed: emails appearing in Teams. 

Simplest way to demonstrate is an example. What I'm doing is setting up a new Flow in Office365. So you'd need Office365, which seems a reasonable assumption as you're using Teams. 

For this example I created a new mailbox ( Every email to that is going to get posted to my Teams site into a "Notifications" group. 

Create an incoming Webhook in the Teams channel

The first step is a webhook in teams, which basically becomes a URL where we can send JSON data to: in this case we'll be sending the body of an email (you have to give it a good image of course.)

Creating a new webhook in Teams

Fill it out and hit the Save button (that button is off the bottom of the page in my screenshot)

Once it's saved, scroll down and note the URL: you can keep this tab open or take a copy and paste it somewhere else as you'll need it later.

Find and make note of the URI

After that, it creates a post in the channel to let everyone know there's a new incoming Webhook:

Create the Flow

Next up we need to put the smarts in.

As a pre-condition to this, I made a blank Office365 mailbox. This might be the only drawback really. You could point this to your own mailbox though to avoid the cost of needing another O365 license (as we'll see later).

Browse to the Flows site: and once you're authenticated, Click on "My flows".

Click on "Create from blank" to make a new Flow.

When the Trigger search comes up, type in "Outlook" or scroll down... you're looking for the one marked below:

Find the right trigger

If you're anything like me, seeing that list started me thinking about other stuff I can do with this. Anyhow...

At this point you'll need to connect it to an Office365 mailbox. I put in my credentials for the new mailbox. Once that's done it connects/authenticates and you can choose what email folder to monitor:

Choose a folder to monitor

Click "New Step" and "Add an action":

Type in or scroll down to find "HTTP":

Now to fill in the relevant detail: look at the image below.

The Body is where the magic happens: we're sending some JSON as a POST to the web service and as part of that we're adding dynamic content, being the email body. 

To get the fancy "Body" section in there, click on "Add dynamic content (bottom right) and it gives you a bunch of stuff you can drag in from the email, as seen below. (More lightbulbs going off when I saw this list!)

I like those options...

Note that the JSON editor is pretty quirky especially when you add the HTML body section. I found that I had to click the Body section in, and then go edit and add the JSON around it.

Now just give the Flow a name (top centre) and click Create flow to save it.

You'll then need to click "Done" (top right)

Test it

Now, to give that new setup a test... I sent an email to the smtpnotifications mailbox. Sure enough it comes through... pretty quickly too.

Happy to say it works well and is doing what I need it to do. It has much more potential than just a straight email notification as well: due to the incredible versatility of the Flow, this could be updated with some much more functional logic, such as posting certain notifications to different channels etc.