How To Change An Email Subject In Power Automate
Power Automate can be used to change an email subject line. There is no dedicated flow action to do this. However, we can call the Microsoft Graph API with the Outlook Send An HTTP Request action and use it to change the email’s subject if we know the right endpoint. Best of all, it doesn’t require any premium licensing.
Table of Contents
• Introduction: The IT Helpdesk Case Id Automation
• Configure The "When A New Email Arrives" Trigger Settings
• Change The Email Subject Using The Microsoft Graph API
• Run The Flow To Update An Email Subject In Power Automate
Introduction: The IT Helpdesk Case Id Automation
The IT helpdesk at a financial services company tracks each case by assigning it a unique case id. When a new request for help email is received in their inbox the helpdesk uses Power Automate to change the subject line to include a Case Id.
For example, [Case Id #1] appears at the end of this email’s subject line.
Configure The “When A New Email Arrives” Trigger Settings
Open Power Automate and create a new automated flow using the Office 365 Outlook – When A New Email Arrives (V3) trigger. Choose the Folder named Inbox.
Go to the trigger’s Settings and enable Split On. This tells Power Automate to evaluate each email individually as it arrives in the inbox.
We also want to determine whether the flow needs to add a Case Id or if it already has one.
Use this expression in the Trigger Conditions to only change the subject line of emails with no Case Id.
@not(contains(triggerBody()?['body/subject'],'[Case Id#'))
Change The Email Subject Using The Microsoft Graph API
The new email subject line should include the original subject and then append a tracking number to the end. Add a Data Operations – Compose action to the flow with the following values in the Inputs field. In this tutorial we will use a hardcoded value since the focus is on how to update the Subject Line.
There is not any Power Automate action to change a subject line so we must use the Microsoft Graph API instead. Insert the Office 365 Outlook – Send An HTTP Request action into the flow and select the PATCH method.
Use the following URI to update the message object.
https://graph.microsoft.com/v1.0/me/messages/@{triggerOutputs()?['body/id']}
Supply this JSON to the Body of the action.
{
"subject": "@{outputs('Compose:_New_Subject_Line')}"
}
Write this code in the Content-Type field.
application/json
Run The Flow To Update An Email Subject In Power Automate
That’s all we need to change the email subject line of an incoming message. Press the Test button in the Power Automate editor and then send an email to the target inbox.
The flow will complete successfully.
And the email subject line will be updated to include [Case Id# 1] at the end.
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps & Power Automate articles sent to your inbox each week for FREE
Questions?
If you have any questions or feedback about How To Change An Email Subject In Power Automate please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.
Hello Matthew
Thanks for the article but I realised that I can use only the follwoing Expression for the trigger condition:
@not(contains(triggerBody()?[‘subject’],'[Case Id#’)) your one with [‘body/subject’] was not working as expected. I never got it triggerd.
Cheers
Michael
Michael,
Which Power Automate editor did you use – New or Classic? I want to know this because the New editor is still in preview and prone to bad results even with the correct code. I used classic to write the article.
Hello Matthew
Well I am using the old one, I don’t like the new one.
A kind of pseudo Nintx implimantation thought.
Here at the communit site I found the same issue (postet Aug-2023):
https://powerusers.microsoft.com/t5/General-Power-Automate/Triggers-in-When-a-new-email-arrives-in-a-shared-mailbox-V2/td-p/2007144
Mattew, I had the same issue as Michael and I am on the classic version. I made the change as Michael has indicated removing body/ and it worked great. Thanks!
In the scenario where you’re adding a case ID, how would dynamically get the right case ID to add to the subject?
Gina,
I chose not to make it dynamic in this tutorial to focus the lesson more narrowly.
But if you want to do it you should create a new SharePoint list called App Settings. Then have two columns: Key and Value. Insert a new row with the key being “Case ID Current” and the value being 1.
Then each time you add a new case number increment the Case ID Current by 1 in a new flow action.
Enjoy!
Thank you for sharing, that’s really helpful. In my case, I tried it in a shared mailbox and unfortunately, it didn’t work. Do you have any idea what could be the reason for this?
Sam,
A different endpoint is required for shared mailboxes. Use the shared mailbox address and replace the {} brackets above:
https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/messages/@{triggerOutputs()?[‘body/id’]}
I am using a Compose action, how will my expression for creating a dynamic email id of a user, that can be used on email action trigger? as AssignedTo?
Hello, Matthew:
I’m testing with a sharemailbox, but I get this error after some successful executions. Can you help me?
Carol,
Suggest you start troubleshooting by using the Outlook HTTP action and then send an update. Outlook HTTP is a standard action. This is the Office 365 Users action.