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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Attaching multiple fil...
Power Automate
Answered

Attaching multiple files to an email

(0) ShareShare
ReportReport
Posted on by 32
Hi there,
 
I created a workflow to automatically attach all files in a SharePoint folder to an email whenever I save a specific file in that folder. Here's an overview of my flow:
 

 
After running for 14 minutes, the flow failed with this error message:
"Action 'Send_an_email_(V2)_2' failed: Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'."
 
Does anyone know how to resolve this issue?
Categories:
I have the same question (0)
  • Suggested answer
    Pstork1 Profile Picture
    69,397 Most Valuable Professional on at
    Take a look at Step 4 in this blog post I wrote.  It shows how to append a file to an array variable so you can use the array in an email.  

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
  • Suggested answer
    Tomac Profile Picture
    4,061 Moderator on at
     
    You'll need to adjust your flow. You can't attach files by file identifier - you have to attach the whole file to an email.
     
    Before your Append To Array action, use a Get File Content action with that file identifier to get the file. Then append it to your array using this array format:
    {
       "contentbytes": {
          "$content-type": "@{outputs('Get_Attachment_(V2)')?['body/contentType']}",
          "$content": @{outputs('Get_Attachment_(V2)')?['body/contentBytes']}
       },
       "Name": "@{outputs('Get_Attachment_(V2)')?['body/Name']}"
    }
    Note that you'll need to adjust the dynamic content in this example to match your flow's actions. My example uses files gathered from email attachments, you'll be using the outputs of your Get File Content action.
     
  • V_Tiger Profile Picture
    32 on at
    , thank you for your input. I have modified my flow as per your instructions. However, when I attempt to enter the expression you provided in the "Expressions" tab, adjusted to the actions I'm using, I receive an error message indicating that the expression is invalid. Below is the adjusted expression and a screenshot of the updated flow. What do you see I'm doing wrong?
    {
       "contentbytes": {
          "$content-type": "@{outputs('Get_file_content')?['body/contentType']}",
          "$content": "@{outputs('Get_file_content')?['body/contentBytes']}"
       },
       "Name": "@{outputs('Get_file_content')?['body/Name']}"
    }
  • Suggested answer
    Pstork1 Profile Picture
    69,397 Most Valuable Professional on at
    Try the following instead.  When you do the Get File Content it provides the already formatted Content.  Its pickable from the Dynamic content dialog.  And make sure not to put quotes around the file content, only around the name.
     

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
     
     
  • Verified answer
    Tomac Profile Picture
    4,061 Moderator on at
     
    That code snippet was formatted to copy/paste directly into the Value field, the expressions would be automatically inserted. This is because the entire snippet isn't an expression, but there are several individual expressions contained within it.
     
    In your comment below, the green parts are the expressions. The rest is plain text for the value. If you want, you can edit out the green parts (expressions) and then add them into your value in the right places.
     
    Now that we can see all of your flow's actions the snippet can be customized to your flow, so here's a snippet you can copy/paste into your Value field with the dynamic content already customized to your flow:
    {
       "contentbytes": {
          "$content-type": "@{triggerOutputs()?['body/{ContentType}']}",
          "$content": @{body('Get_file_content')}
       },
       "Name": "@{triggerOutputs()?['body/{FilenameWithExtension}']}"
    }
     
  • V_Tiger Profile Picture
    32 on at
    @Pstork1, I tried the code you provided in your last comment. Although the email was sent with attachments, the attachments were not in the expected formats (i.e., ".xlsm" and ".xlsx"). They appeared without any format. (Please see the screenshot below). On a positive note, the code provided by @Tomac worked as expected. Thank you both for your help!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 957

#2
Valantis Profile Picture

Valantis 847

#3
Haque Profile Picture

Haque 609

Last 30 days Overall leaderboard