Skip to main content

Notifications

Community site session details

Community site session details

Session Id : STyeNFJwV4n6qMY5nmL6lP
Power Automate - Building Flows
Answered

Sending an email with variable number of attachments

Like (0) ShareShare
ReportReport
Posted on 19 Jun 2019 20:04:15 by

I built a flow that drafts a specific type of email that my colleague sends out regularly. This email has to have PDF attachments that are pulled from one of our SharePoint libaries. Normally the emails contain two, but occasionally they contain three.

 

My issue is that the Send Email action fails if I've specified that there is an attachment name but instead the action receives a null value (since there is no attachment). 

 

What I'm looking for is a way to create a custom Send Outlook Email connector that has flexibility built into the attachments section - the connector might have room for five attachments, but if an attachment isn't supplied, it doesn't error out. Does anyone know how I could go about doing this?

 

I even started to recreate the entire email generator in PowerApps, but I found that PowerApps can't pass PDFs to the table it requires for adding attachments to an email (it can only handle media files with their content stored as BLOBs).

  • MarcelGerh Profile Picture
    4 on 20 Dec 2023 at 13:04:39
    Re: Sending an email with variable number of attachments

    There were three mistakes:

     

    1. In the Array there is written "ContentByte" and is has to be "ContentBytes".
    2. Also in the newest PowerAutomate Version, the body of the ContentBytes has not to be 

    body('Get_file_content') and not body('Get_file_content')?['$Content'].

    That has changed since October 2023.
    3. In the Array around the contents of "Name" and the "ContentBytes", there are NO " " allowed! (no quotation marks)
    If there are quotationmarks, the received PDF's in the mail are fully blank.


    I hope I could help someone out here, searching for the same problems! 

    Here is a helpful video about it:
    https://www.youtube.com/watch?v=is5HSeXGdgk

  • MarcelGerh Profile Picture
    4 on 20 Dec 2023 at 11:46:36
    Re: Sending an email with variable number of attachments

    Same here.
    I Think they changed something here...

    But if I'm only using the body, then my PDF is just Blank - I can open it, the amount of pages are right, but nothing is visible. 

    Does someone know what the problem is?

  • RBoneck Profile Picture
    409 on 11 Jul 2023 at 00:31:27
    Re: Sending an email with variable number of attachments

    This looks like it works until I try to click on the attachment and then it says it can't find the file.

    What did work for me was exactly this except for in the 'Append to array variable' action, instead of


    body('Get_file_content')?['$Content']


    in the ContentBytes field, I needed just


    body('Get_file_content')

    and then it works great!

  • DaynaBee Profile Picture
    309 on 09 Jan 2020 at 18:08:16
    Re: Sending an email with variable number of attachments

    @v-zhos-msft 

    You saved my life!!! the reference link cleared up my confusion. Thank you!

  • Community Power Platform Member Profile Picture
    on 21 Jun 2019 at 20:13:02
    Re: Sending an email with variable number of attachments

    @v-zhos-msftThank you so much! I spent 30 hours trying to devise workarounds before you shared this with me. I didn't know supplying the attachments field with an array would get around the issue. The only change I made to what you described was that I entered "ContentBytes" instead of "ContentByte" (for any users who try this method). I really appreciate the help.

  • Verified answer
    v-zhos-msft Profile Picture
    on 20 Jun 2019 at 02:34:19
    Re: Sending an email with variable number of attachments

    Hi @Anonymous ,

    As you said, the pdf files are in a SharePoint library.

    Are there other files you don't want to send as attachments in that library?

    I have made a test on my side, I save the PDF files in one library without other files.

     

    Capture.PNGCapture1.PNG

    Expression reference:

    Capture2.PNG

    Best Regards,

    Community Support Team _ Zhongys

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 18 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 14

#3
Churchy Profile Picture

Churchy 12

Overall leaderboard
Loading started