web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get contents from text...
Power Automate
Answered

Get contents from text file with different file names and send e-mail

(0) ShareShare
ReportReport
Posted on by 53

Hi

 

Though this would be easy, but can't fathom it out, have a flow that creates a text file in one drive, each text file has a unique ID (PNL ate, Time including seconds eg "PNL Tue 07 May 2024 14 35 47.txt")

 

Now trying to write a flow so that when a new file is created, the contents of that file are read and put into an email for sending, have tried "Get file content" and "Get file content using path" but they both seem to require the name exact name of the file, which obviously changes every time (and believe cant use wildcards), and I cant figure out how to make it work

 

Have tried below, but then I also cant get the contents of the "Get file Content" action  to show in the e-mail

 

Thanks for any help

 

richardj5_0-1715090443886.png

 

 

Categories:
I have the same question (0)
  • Verified answer
    ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Hi @richardj5 

     

    Pls refer the sample flow.

     

    Pass the 'File Identifier' from trigger to "Get file content" action:

    ManishSolanki_0-1715095688587.png

     

    Next, add compose action to get the text or content from the previous action:

    ManishSolanki_1-1715095751758.png

     

    Finally, pass the output of compose action in the email body:

    ManishSolanki_2-1715095808425.png

     

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

  • richardj5 Profile Picture
    53 on at

    Hi

     

    Yes this worked, however is converting the output to HTML so is coming out wrong in the e-mail (the message can only be read by a machine in plain text format), tried adding "HTML to Text" converter but still coming out in wrong format, just had a search and believe it is not possible to send plain text emails (which is ridiculous)

     

    Need to try and find a way round that now!

     

    Many thanks

     

     

     

     

     

  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Hi,

     

    I have one more solution for you to send email body in text format, but it requires premium connector. 

     

    Here are the steps:

    Use "Invoke an HTTP request" action inside 'HTTP with Microsoft Entra ID (preauthorized)' connector. 

    ManishSolanki_0-1715099950534.png

    To make a connection, enter 'https://graph.microsoft.com' in both parameters and select the user if pop up comes out:

    ManishSolanki_1-1715100022739.png

    We will enter 'contentType' as 'Text' to send email in text format:

    ManishSolanki_2-1715100101846.png

    Method: POST

     

    Url of the request: https://graph.microsoft.com/v1.0/me/sendMail

     

    Headers:

    Content-Type                     application/json

     

    Body:   

    {
    "message": {
    "subject": "text format email",
    "body": {
    "contentType": "Text",
    "content": "@{outputs('Compose')}"
    },
    "toRecipients": [
    {
    "emailAddress": {
    "address": "yyy@xxx.onmicrosoft.com"
    }
    }
    ],
    },
    "saveToSentItems": "false"
    }

    Pls adjust the sender email address in the email body (highlighted in red color)

     

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

  • richardj5 Profile Picture
    53 on at

    Many thanks for helping, flow has failed with following error

     

    "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format."

     

    I have changed the Subject (as it must be specific) and added who the e-mail is gong to after the "toRecipents" as per below (and changed the senders address as described)

     


    "message": {
    "subject": "XX",
    "body": {
    "contentType": "Text",
    "content": "@{outputs('Compose')}"
    },
    "toRecipients": "test@test.com"
    {
    "emailAddress": {
    "address": "xx@xx.onmicrosoft.com"
    }
    }
    ],
    },
    "saveToSentItems": "false"
    }

     

    Thanks again

  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Hi,

     

    There is an error next to property "toRecipients". The body contains only the recipient(s) of the email but not sender. So, you need to add a recipient as mentioned below.

     

    Pls use the below JSON in body:

    {
    "message": {
    "subject": "XXXX",
    "body": {
    "contentType": "Text",
    "content": "@{outputs('Compose')}"
    },
    "toRecipients": [
    {
    "emailAddress": {
    "address": "test@test.com"
    }
    }
    ],
    },
    "saveToSentItems": "false"
    }

    Pls adjust subject & email address marked in red in the above JSON code.

     

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

     

  • richardj5 Profile Picture
    53 on at

    Hi

     

    The flow has now run successfully, but I didn't receive an e-mail?

     

    Sorry but I don't understand/not sure where to put the recipients address in the JSON?

     

    Thanks again

  • richardj5 Profile Picture
    53 on at

    Hi

     

    Been playing around for a few hours and have got the e-mail to be sent in plain text to me, but it comes from me, can I set who the e-mail is from as the receiver of the e-mail only accepts plain text e-mails from trusted e-mail addresses under 35 characters long, my e-mail is over this limit so we have set up one that meets the required specification, any way to do this?

     

    Many thanks again for all your help, I've learnt a lot in the past few hours 

     

    Richard

     

     

     

     

     

     

  • Verified answer
    ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Hi Richard,

     

    One easy solution is to get an account created for this use case from admin team. Assigned mailbox to that account. 

     

    In power automate flow, you can use 'Get user profile' action to get the ID of the user by passing the email address:

    ManishSolanki_0-1715144181628.png

    The output of this action returns the user ID which can be used as a sender by using different graph api end point for sending email:

    https://graph.microsoft.com/v1.0/users/<dynamic user id>/sendMail

     

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

  • richardj5 Profile Picture
    53 on at

    Morning

     

    That worked perfectly, thanks again for all your help, much appreciated 👍

     

    Richard

  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Glad to know 😊 🙌

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard