Parse Emails With Power Automate

Last week, I wrote about how to use Power Automate to add automation to everyday tasks like emails. One of the examples I gave was to notify myself when vacation requests arrive so I can approve them as quickly as possible. Emails like these frequently have links like “click here to view the request” that take you to the item needing attention. It sure would be nice if we could extract that link and do something useful with it, right?

Regular expressions are a great way to parse text like this to extract useful details. Unfortunately, Power Automate doesn’t seem to have native support for regular expressions, but there are connectors from a third-party provider Plumsail. I took it for a test run today, and it worked pretty well. So, let’s take a look at the steps.

In order to use the Plumsail connectors, you’ll need a Plumsail account & API key. You can register for an account here, and create an API key here. Keep your API key handy, and head over to Power Automate.

In my workflow, I added the Plumsail Regular Expression Match connector as a new action after my “When a new email arrives” trigger action. If it’s the first time using a Plumsail connector, it will prompt you for your API key and a connection name.

After you’ve specified your connection name & API key, the connector UI changes to what you’d expect for a regular expression: Pattern & Text. The output of this control is a collection of matches, and the dynamic content will adjust based on the capture groups (parentheses) specified in your pattern.

In the screenshot above, my regular expression will search the email body for the “please click here” hyperlink and capture the URL. I can then dump this URL into the message to myself in Slack. Works great!

@mentions in Slack From Microsoft Power Automate

In my last post, I demonstrated how to create a basic workflow that posts to Slack when email is received that matches specified criteria. Pretty cool, right? Sometimes you want to make sure that somebody gets a notification about these important messages that you’re posting, though. Slack has a built-in way to do this with its mentioning system.

Unfortunately, mentioning a user or group from Power Automate isn’t as straightforward as you might expect. When you specify message text like @somegroup it just shows up in Slack as that text.

The reason it doesn’t work is because the text isn’t parsed to use special formatting required by Slack for things like mentioning. The good news is that the workflow widget will do this work for you if you enable Parse Mode=full in the advanced options.

The bummer about using Parse Mode=full is that you can’t include other object entities e.g. an email object’s subject. Enabling full parsing gives us a great hint at the solution if we look at the run results…

So if we know the “special formatting” values, we can use those in messages? Yep!

It’s not a perfect solution because there doesn’t seem to be a good, built-in way to retrieve the special formatting for a Slack user or group required to @mention them from Power Automate, but it does give you a couple ways to accomplish the goal of mentioning them in messages you post. You can enable full parsing in advanced options to mention from a static text message, or determine the special formatting for a user or group yourself to use in a dynamic message constructed from other entities in your workflow!

Everyday Automation With Microsoft Power Automate

One of my favorite tools these days is Microsoft Power Automate (formerly Microsoft Flows). Power Automate lets you visually construct workflows for all kinds of things, and I’ve found it to be an incredibly powerful way to automate tasks. Here are some examples:

  • Post in Slack when an email is sent to a shared mailbox
  • Post status tweets from a SaaS provider’s Twitter account in Slack
  • Send an SMS text message when a critical process fails

The thing I love most about Power Automate is that you can make sophisticated workflows very quickly, and they don’t require hosting or deployment. You just create, save, and it’s live.

Many of my workflows start by me realizing that I didn’t notice a certain category of emails quickly enough or that I need to give my team better awareness of an event. For example, I wanted to ensure that expense reports get approved right away so that employees get reimbursed, so I created a workflow to send a direct message in Slack whenever I get an approval request email from the expense system. Another common example has been to notify my team when applications report failures through various means.

Power Automate boasts a “low code” experience, but most of the workflows I’ve created have required coding skills and creative troubleshooting to figure out. That said, you can still do useful things with pretty much zero code as long as you’re not trying to get too fancy. In this post, we’ll build a simple workflow that posts a notification to Slack when an email comes in.

We begin by creating a new automated workflow. Automated workflows always start with a trigger, so I’m going to pick “When a new email arrives.” Another option that’s been useful to me is “When an email arrives in a shared mailbox,” but as you see in the screenshot below, there are many options to explore–and many that have nothing to do with email, as well.

If you’re automating something for an unmonitored mailbox, you may not want additional criteria, but I’m usually looking for something like an email from a specific sender with a certain subject. So, the next step in our workflow will be a Condition so we can specify which criteria we care about.

The last step in our workflow will be to define what happens when the condition is met or not met. We want our sample workflow to send a private message in Slack. To accomplish this, I’ll add the “Post message to Slack” step and enter my Slack username for the channel and some text for the message. Instead of hard-coded message text, you could also include attributes from the email message entity, similar to those used in the condition step.

The final step is simply to save it. That’s it. When an email arrives, the workflow checks it against the conditions you’ve defined, and performs the corresponding Yes/No actions–in this case send ourselves a message in Slack.

%d bloggers like this: