Understanding The Trigger: Outlook.com – When a New Email Arrives

This blog and video series ‘Understanding The Trigger’ (UTT) is looking at each trigger in the Microsoft Flow workspace. The aim is to understand what they do, how to use them and building an example of them being used to allow us to have a greater understanding of the breadth of uses for Microsoft Flow!

The Trigger

When an email is received in your Outlook.com account, you may want to have some business logic run against this email, maybe you want to check if there is a response to a question or you want to log the money you have been spending at a certain website. Well this trigger, is  responsive and can react as soon as an email comes in to your account. It can be found in the ‘Standard’ trigger category under the ‘Outlook.com’ section.

Functionality

When first adding the “When a New Email Arrives” trigger you will simply see a folder option that will pick your inbox. You can press the folder icon and it will bring back a list of the default folders and any folders that you have created.

Selecting the advanced options reveals an additional eight options that will allow you to search the subject, check if an importance flag is set or simply check who an email is from. Now lets have a look and breakdown the advanced options on this trigger.

To

This simply checks the recipient email address, you can check for multiple addresses using a semicolon. This of course can be ignored if you’re simply checking your own personal email address.

CC

Similar to ‘To’ this checks the email address(s) that have been cc’d into an email, again this can check   for multiple addresses using a semicolon.

To or CC

This effectively combines both To and CC, allowing you to check both fields for a single or multiple email addresses, again this can check  for multiple addresses using a semicolon.

From

Exactly like both To and CC, this simply checks the ‘From’ field email address(s) that you have been sent an email from, again this can check for multiple addresses using a semicolon.

Importance

The importance field allows you to check if the received email has any importance or simply low, normal or high.

Has Attachment

The has attachment field is a Boolean field of Yes(True) or No(False), however, at the drop of the dropdown is an empty selection, if you select this it will simply ignore this section.

Include Attachments

Now this is slightly different to ‘Has Attachment’ by actually including the attachment for the Flow, rather than checking if it does or it doesn’t have an attachment.

Subject Filter

This looks at the subject line and checks your entry into this field against the subject. If the subject contains your entered value then it will trigger as a ‘true’ response.

Example

As a user I want to use the Microsoft Flow ‘Outlook.com – When a New Email Arrives’ trigger to check if an email has an attachment and if so save it to my personal OneDrive so that I can have a backup copy.

User Story

Firstly, we want to add the ‘ Outlook.com – When a New Email Arrives ‘ trigger. This will then provide us with, as we saw previously, the default inbox selected.

We’re going to want to check for attachments, as per the user story, so secondly we want to open up the advanced options for this trigger.

We now want to check that the email ‘Has Attachment’, so we set this to ‘Yes’ so that we skip any email without an attachment and then we also want to have the file within our Flow cycle, so we need to set ‘Include Attachments’ to ‘Yes. This will now check if we have an attachment and if we do we will grab that attachment from the email.

Now we need to add a OneDrive ‘Create File’ action, pass in the ‘Attachments’ variable which in-turn will add the ‘Apply to Each’ condition. This is so that if there is more than one attachment it will cycle through each attachment, creating a file.

Now we need to tell the action what it is exactly that we want to happen for each attachment. We’re already creating a file, but what is the file contents? Before we complete this section, I’ve created an ‘Email Attachments’ folder in my personal OneDrive.

Now we need to complete the OneDrive Create File action information. To do this we firstly select the folder which we want the file to be created, as mentioned before, I created an ‘Email Attachments’ folder, so I have selected this. Then we want to pass ‘Attachments Name’ variable for the ‘File Name’ section and the ‘Attachments Content’ for the ‘File Content section (shown below).

Demonstration

We can test this using live data from Outlook which will pull the last email you received and run your Flow against that. So, I have a TDGi Global Hack email as my last email received, it contains a promotional image for our team (Global Hack Dream Team).

When running this I then expect the image to be pulled from my email, created in the ‘Email Attachments’ folder and named correctly.