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 / Sending email attachme...
Power Automate
Unanswered

Sending email attachment using array variable fails due to "file content" being null

(0) ShareShare
ReportReport
Posted on by 1,393

I'm building a flow where I want to be able to attach a variable number of files to an email sent using the Office 365 Outlook "Send an email (V2)" action. This action allows you to specify the name and file content of each attachment individually, but in this case, I need it to be scalable (allow attaching one file, two files, three files, etc. as needed). A trick I learned a while back (for sending SharePoint list item attachments as email attachments) was to create an array variable with the file name and content defined as properties, like this:

ChadVKealey_0-1613403209437.png

Then, in the "Attachments" section of the send email action, switch to "text mode" and drop in the array variable, like this:

ChadVKealey_1-1613403306283.png

This seems to work some of the time, but more often than not, the send email action fails, reporting that the Attachment Content cannot be null or empty: 

ChadVKealey_2-1613403425146.png

I was testing this yesterday afternoon in preparation for a meeting with a client today and it seemed to be working reliably. When I replicated the steps into the "production" flow and tested it, the action consistently fails. I then went back to the test flow and that, too (which is configured exactly as it was yesterday afternoon) is now failing consistently. 

 

What I think will work (if I can figure out how) is to have a "delay until" loop that runs until the "ContentBytes" property of each item in the varFileAsArray variable is not equal to null (although, it would be sufficient to wait for the last item in the array, since they'd be appended in serial order). I just don't know how to write the expression to extract a property from the last object in an array.

Categories:
I have the same question (0)
  • Paulie78 Profile Picture
    8,424 Moderator on at

    To get an property of the last element of an array you can do something like:

    last(outputs('arrayName')['propertyName']

    But it sounds like your problem is more fundamental - if you have elements of your array which have no file content, then an error is what you would expect. You could filter the array to remove the null elements, but presumably you are expecting file content to be present.

     

  • ChadVKealey Profile Picture
    1,393 on at

    OK, the plot thickens, and frustration grows. Now, the test flow is working again. Here are the exact steps in that flow:

    ChadVKealey_0-1613404726750.png

    These are the exact steps in the "production" flow (which is consistently failing): 

    ChadVKealey_2-1613404808106.png

    Now, the two flows are different prior to these two actions (one is triggered "for a selected file" in SharePoint, the other is triggered on submission of a MS Form), but both have identical "Get file properties" and "Get file content" actions, the output of which are being used to create that array variable. So, I'm at a loss to explain why it works in one flow but not the other. I think there is some fundamental flaw here (in the platform) that is in one case waiting for the append to array to actually finish before allowing the send email action to proceed but in another case, not waiting. Having a wait/delay step (as I suggested previously) is a potential workaround, but it's not a fix for the issue.

  • Paulie78 Profile Picture
    8,424 Moderator on at

    I don't think there is a problem with the platform, I also don't think adding a delay would make any difference. I would suggest having a look in your run history at a failed run and then taking a look at the contents of your array variable.

  • ChadVKealey Profile Picture
    1,393 on at

    I did that. In the flow that's working, the "append to array" looks like this:

    ChadVKealey_0-1613406747676.png

    When I "click to download", a separate tab opens with the structure of the array, including the name of the file and the content. In the flow that's failing, this is what the output of the "append to array" action looks like:

    ChadVKealey_1-1613406938454.png

    The configuration of the two actions is identical. In the non-working flow, the "Get file content" action was immediately above the "append to array" action, while in the working flow, there are a number of "initialize variable" or "set variable" steps in between (so, a built in delay of probably a few microseconds, if that?).

     

    I also checked the output of the "Get file content" actions in each flow, and both are identical. So, that step is - or appears to be - completing properly in both cases.

  • cgreenmzr Profile Picture
    53 on at

    @ChadVKealey I realize the last response on this post was over a year ago, but I'm running into this exact issue.

     

    I'm grabbing my attachments from a SharePoint list and I can see the attachment content in 'Get attachment content', but when I append to my variable, I get the name of the file, but not the ContentBytes, which shows as NULL.

  • cgreenmzr Profile Picture
    53 on at

    Sorry, meant to include a screenshot:

    cgreenmzr_0-1646930080831.png

     

  • ChadVKealey Profile Picture
    1,393 on at

    Can you add a screenshot of how that "append to array" is configured? I'm unable to replicate the issue myself.

  • cgreenmzr Profile Picture
    53 on at

    Yes, below. I feel like I should be converting the Attachment Content (ContentBytes) to a different data type/format.....thoughts? 

    cgreenmzr_0-1646940262934.png

     

  • ChadVKealey Profile Picture
    1,393 on at

    Weird...that's exactly what I've got in my test flow and it's working fine. Do you get the same behavior regardless of the file that's attached? I know that images (vs. other kind of files, like Word docs) are stored in SharePoint as base64 files, but that shouldn't matter here. Also, I'm testing with .png files as well, so if it were a file type issue, it should be happening for me, too. What doesn't make sense to me is that the data is clearly there, so I can't explain why it's not going into the variable. 

     

    Just as a test (and I doubt it'll make a difference), you could add a Compose before the Append to variable, pop the "Attachment content" into that, than pull the output of that compose into the ContentBytes in the Append action (as shown below):

     

    ChadVKealey_0-1646959987375.png

     

  • cgreenmzr Profile Picture
    53 on at

    While my use case is a little different (I'm creating a ticket in Zendesk) I just recorded a video walking through the result of my flow. I did add a 'Compose' but that didn't make a difference. 

     

    https://drive.google.com/file/d/1_CvZ1Wv6pWpYAI7beNeJRJ6X5x_hjY5q/view?usp=sharing

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 785

#2
Valantis Profile Picture

Valantis 669

#3
Haque Profile Picture

Haque 563

Last 30 days Overall leaderboard