- Home
- Guides
- AI Builder & AI
- How to auto-reply to Outlook emails with a trained OpenAI assistant and Power Automate
How to auto-reply to Outlook emails with a trained OpenAI assistant and Power Automate
Build a Power Automate flow that sends each new Outlook email to an OpenAI Assistant trained on your own documents, then replies to the sender with the answer. Questions your documents do not cover get a polite hand-off message instead.
Jump to a step (15)
Support inboxes fill up with the same questions, and the answers already sit in a troubleshooting guide or company document. Someone still has to read each email, find the right section and type a reply by hand. That slows response times and ties up staff on repeat questions.
This build connects three pieces. An OpenAI Assistant holds your instructions and your documents. A Power Automate flow starts when a new email arrives in Outlook, sends the subject and body to the Assistant through the API, waits for the answer, and replies to the same email.
The Assistant only answers from the files you upload. When an email asks something outside those files, such as "Who is the president of the US?", it replies that it cannot help and that an agent will get back to the sender.
What you need
- A Microsoft 365 mailbox in Outlook
- Power Automate with a license that includes the premium HTTP action (Power Automate Premium or a trial)
- An OpenAI platform account with prepaid API credit
- The documents you want the bot to answer from, such as a troubleshooting guide and company information
Step by step
0 of 15 done-
01
Create an OpenAI platform account and add credit
Go to
platform.openai.comand sign in or create an account. Add a payment method and buy some credit. OpenAI charges by usage, so set a usage limit on the account in case something goes wrong in the flow and it keeps calling the API. -
02
Create the Assistant
Open the
Dashboardmenu and selectAssistants, then create a new assistant. In the video I name itAutomated customer support replies.Under the name you see the assistant's unique ID (it starts with
asst_). Copy it. The flow needs it later. -
03
Add the instructions and pick a model
Paste your instructions into the
Instructionsbox. The instructions in the video tell the Assistant to:- Expect an email subject and an email body in every message
- Reply only with information from the uploaded documents
- Write professional, precise replies and begin by greeting the sender
- Reply that it cannot help and an agent will get back to them when the answer is not in the documents
- Use
<br>tags where a new line starts, so the email reply keeps its line breaks
For the model I select
gpt-4o. -
04
Turn on File search and upload your documents
Switch on
File search, then useFilesandClick to uploadto add your documents. In the video I upload two files: company information and a list of technical issues and solutions. These files are the only knowledge the bot will use. -
05
Test the Assistant in the Playground
Select
Playgroundand send a test prompt that looks like a real email, with anEmail subject:and anEmail body:. SelectRun. The answer should match your document and include<br>tags for line breaks.Then send an unrelated question, such as who the president of the US is. The Assistant should reply that it cannot help with that. If it answers anyway, tighten the instructions.
-
06
Create the automated cloud flow
In Power Automate, select
Createand thenAutomated cloud flow. Name it something likeOutlook email replies with OpenAI Assistant. Search foremailand pick the Office 365 Outlook triggerWhen a new email arrives (V3), then selectCreate.If you already have an older version of this flow running, turn it off first so two flows do not reply to the same email.
-
07
Store the API key and Assistant ID in variables
Add an
Initialize variableaction namedOpenAI API, typeString. For the value, go back to the OpenAI dashboard, openAPI keys, selectCreate new secret key, and copy the key. You cannot view the key again after you close the dialog, so save it somewhere safe.Add a second
Initialize variableaction namedAssistant ID, typeString, and paste the assistant ID you copied earlier. Renaming each action to match its variable makes the flow easier to read. -
08
Create a thread and send the email with an HTTP action
The Assistants API normally takes five calls: create an assistant, create a thread, add a message, create a run and read the output. The assistant already exists, and you can create the thread and add the message in one call, so the flow only needs three HTTP requests.
Add an
HTTPaction and set:URI:https://api.openai.com/v1/threadsMethod:POST- Headers:
Content-Type=application/json,Authorization=Bearerfollowed by theOpenAI APIvariable,OpenAI-Beta=assistants=v2 Body: a JSON object with one user message, for example{"messages":[{"role":"user","content":"Email subject: [Subject], Email body: [Body]"}]}
Replace
[Subject]and[Body]with theSubjectandBodydynamic content fromWhen a new email arrives (V3). -
09
Test once and parse the thread ID
Save the flow, select
Test, chooseManually, and send any email to the mailbox to trigger it. Open the HTTP action's output and copy the wholeBody. It contains the new threadid.Back in edit mode, add a
Parse JSONaction. SetContentto theBodyof the HTTP action, selectUse sample payload to generate schema, paste the copied body and selectDone. Rename the action toThread IDso you can find it later. -
10
Start a run with a second HTTP action
Add another
HTTPaction and rename itRun. Set:URI:https://api.openai.com/v1/threads/followed by theidfrom theThread IDParse JSON action, then/runsMethod:POST- The same three headers as before
Body:{"assistant_id":"[Assistant ID]","instructions":"[your instructions]"}
Use the
Assistant IDvariable for[Assistant ID]. In the video I paste the same instructions from the Assistant into this body so the run follows them.Save and test with
Automaticallyand a recently used trigger. Copy the run's output body and add a secondParse JSONaction (rename itRun ID) using that sample, withContentset to theBodyofRun. -
11
Add a delay while the Assistant writes the answer
Add a
Delayaction set to1Minute. In my tests the Assistant needs around 30 to 40 seconds to generate a reply, so one minute gives it room. If you read the messages too early, the reply will not be there yet. -
12
Retrieve the reply with a third HTTP action
Add a final
HTTPaction and rename itOutput. Set:URI:https://api.openai.com/v1/threads/followed by the threadid, then/messagesMethod:GET, because you are reading data, not sending it- The same three headers
- No body
Save and test with the last successful trigger. In the output body, the Assistant's answer sits inside
data, thencontent, thentext, thenvalue. -
13
Reply to the email with the Assistant's answer
Add the Office 365 Outlook action
Reply to email (V3). ForMessage Id, pickMessage IdfromWhen a new email arrives (V3)(selectSee moreif you do not see it).Under
Advanced parameters, addBodyand enter this expression:body('Output')?['data'][0]?['content'][0]?['text']?['value']It takes the first message in the
dataarray (the newest one, which is the Assistant's reply), then the firsttextitem in itscontent, then itsvalue. Save the flow. -
14
Test with a real question
Select
Test, chooseManually, and send an email about an issue covered in your documents. The run waits on theDelayaction for a minute, reads the output and sends the reply. In the video the bot replies with the exact fix steps from the troubleshooting guide. -
15
Fine-tune the replies
Sometimes the bot mentions the name of the source document in the reply. To stop that, edit the first HTTP action and add an instruction to the message content, next to the email subject and body. In the video I add: if the information is not available in the document, reply that you cannot help and an agent will get back to you soon, and do not mention the document reference.
Save the flow and send another test email. Keep adjusting the instructions until the replies read the way you want.
Tips and common problems
- The API secret key is shown only once. Copy it into the variable right away, and create a new key if you lose it.
- When you test the Run action, check that you replaced the sample assistant ID in the request body with your
Assistant IDvariable. In the video the first test fails with an error because the demo ID was still there. - If the reply comes out as one long block of text, add an instruction telling the Assistant to use
<br>tags for new lines. Outlook renders them as line breaks. - If the bot mentions the source file name, add "do not mention the document reference" to the message you send in the first HTTP request.
- Set a monthly usage limit in your OpenAI account so a looping or misfiring flow cannot run up a large bill.
- OpenAI has announced that the Assistants API is being retired in favor of its newer Responses API. Check the current OpenAI API documentation before you build, because the endpoints shown in this video may stop working.
The three API requests in this flow
| Action | Method | URI | What it does |
|---|---|---|---|
| HTTP (create thread) | POST | https://api.openai.com/v1/threads | Creates a thread and adds the email subject and body as a user message |
| Run | POST | https://api.openai.com/v1/threads/{thread_id}/runs | Tells your Assistant to process the thread with your instructions |
| Output | GET | https://api.openai.com/v1/threads/{thread_id}/messages | Reads the messages, including the Assistant's reply |
All three use the headers Content-Type: application/json, Authorization: Bearer [your API key] and OpenAI-Beta: assistants=v2.
Expression used in the reply
body('Output')?['data'][0]?['content'][0]?['text']?['value'] returns the text of the newest message in the thread, which is the Assistant's answer.
Questions
Can Power Automate reply to Outlook emails automatically with ChatGPT?
Yes. A flow triggered by When a new email arrives (V3) can send the email to the OpenAI API with HTTP actions, wait for the answer, and use Reply to email (V3) to send it back to the sender.
Do I need a premium Power Automate license for this flow?
Yes. The HTTP action is a premium connector in Power Automate, so you need Power Automate Premium or a trial. The Outlook trigger and reply action are standard. You also pay OpenAI separately for API usage.
Will the bot answer questions that are not in my documents?
Not if the instructions say so. In the video the Assistant is told to reply only from the uploaded files, so a question like "Who is the president of the US?" gets a reply saying it cannot help and an agent will get back to the sender.
Why does the flow wait one minute before reading the reply?
The Assistant needs time to process the run. In the video it takes around 30 to 40 seconds, so a one-minute Delay makes sure the answer is ready before the flow requests the thread's messages.
