Email classification using Azure OpenAI

Imad Bensisaid
4 min readOct 31, 2023

In this article, I will show you how to sort your organization’s emails by importance and decide whether to process them.

Prerequisites :

  • In this article i will use office 365 and Azure
  • You must be Admin on your tenant
  • Azure Open AI must be enabled on your azure subscription

Use case:

Let’s assume that your organization asks you to classify some emails from certain accounts and store a copy of all important emails. How would you proceed ?

Design

All accounts must forward to a single account, which will be triggered by a Logic App when a new email is received. Then, the body is extracted and sent to Azure OpenAI to be analyzed and determine if it’s important or not

Let’s create the accounts

1- Go to Active users — Microsoft 365 centre d’administration

2- Add new users (my screen is in french)

I have created two addresses with Microsoft 365 Business Basic licenses

  • testemail@uni5-technologies (to recieve the email)
  • testreciever@uni5-technologies.com (which all email will be forward to from testemail@uni5-technologies)

3- Create the forward by selecting your user

Now, all emails sent to testemail@uni5-technologies will be forwarded to testreceiver@uni5-technologies.com

Create logic app

“If you’re unfamiliar with creating a Logic App, I encourage you to search for guides on Google ;-)”

1- Create the connector Office 365 and must to connect our account testreciever@uni5-technologies.com

2- Next step is to create Azure Open ai resource (If you don’t know how to create logic app i let you search on google ;-))

but once is your Azure open ai instance is created, go to the Azure openAI studio

Click on deployments then Create a deployment

Select your model and the name, for my example i took GPT-4 and my model is named emailAI

let’s test a conversation

It works! Now let’s examine the code to determine which API to call. To do this, click on ‘Show the code’

Now we have all the information needed, let’s return to the Logic App and implement the call to our model by using HTTP connector

In my prompt, I explain that I need to check if the following email (retrieved from the trigger) is important or not and respond simply with ‘yes’ or ‘no’.

Then i check the result

the code to check is :

Let’s test :

I sent an email regarding an unpaid bill; let’s check the result.

He said ‘Oui,’ so the condition is TRUE. Our email is important, and that’s good.

Now let’s test with a less important email

I asked testemail to have a coffee if he is available.

the AI said that it is not important, cool.

--

--

Imad Bensisaid

Hi, I'm a cloud architect with experience in designing, building, and deploying scalable cloud solutions on Azure.