Skip to main content
Community site session details

Community site session details

Session Id : 1k//iFWROh8W4zJgK/iwzm
Power Automate - Building Flows
Unanswered

Sending email with populated file attachment as well as file from SharePoint

Like (0) ShareShare
ReportReport
Posted on 14 Oct 2020 03:32:10 by 44

I have a flow that populates a Word doc and converts it into a PDF. 

The data comes from SharePoint which gets it from a form submission in PowerApps.

The user also attaches files in PowerApps which will be stored in the SharePoint list.

 

I need both the converted PDF file as well as the attachments from SharePoint to the sent with the email.

 

I have searched the web far and wide but only every found one or the other solution but not both. I am able to either attach the PDF file OR the SharePoint files but not both. 

 

Please help! Thank you.

Screen Shot 2020-10-14 at 2.30.13 pm.png

This is my flow for getting the attachments from SharePoint. If anyone can help, I'm happy to expand and upload more screenshots.

  • MSSAdmin Profile Picture
    44 on 25 Oct 2020 at 20:21:56
    Re: Sending email with populated file attachment as well as file from SharePoint

    Hi @v-litu-msft,

    I'd appreciate a bit more help with my attachment error 😉

    Or anyone else who might have the solution?

    Thank you!

  • MSSAdmin Profile Picture
    44 on 21 Oct 2020 at 22:25:19
    Re: Sending email with populated file attachment as well as file from SharePoint

    Hi,

    I had used your code before but after changing the code to the base64() function, saving the flow, closing it and then going back in to edit, the code is swapped back to this:

    Screen Shot 2020-10-22 at 9.27.22 am.png

  • v-litu-msft Profile Picture
    on 21 Oct 2020 at 08:22:39
    Re: Sending email with populated file attachment as well as file from SharePoint

    Hi @MSSAdmin,

     

    Please use the base64() function to convert the attachment content:

    base64(outputs('Get_attachment_content')?['body'])

    Screenshot 2020-10-21 162031.jpg

     

    The PDF file part should use the base64() function to process it. 

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • MSSAdmin Profile Picture
    44 on 20 Oct 2020 at 20:38:10
    Re: Sending email with populated file attachment as well as file from SharePoint

    Thank you, dragging the PDF append to array out of the "Apply to each" worked to only attach the one PDF but more than one photo.

    Still can't open the attached files though 😞

     

    Screen Shot 2020-10-21 at 7.35.22 am.png

    Screen Shot 2020-10-21 at 7.37.20 am.png

  • v-litu-msft Profile Picture
    on 20 Oct 2020 at 07:50:06
    Re: Sending email with populated file attachment as well as file from SharePoint

    Hi @MSSAdmin,

     

    Thanks for your reply. The repeated PDF file is caused by you append the PDF file action into a loop, duplicate PDF files depends on the number of attachments files

    Please move the Append to an array action that put PDF file out of the Apply to each action.

     

    Would you mind share screenshots of the Send Email action and Append to array action? I want to know how you configure it, thanks for your time.

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • MSSAdmin Profile Picture
    44 on 19 Oct 2020 at 21:06:59
    Re: Sending email with populated file attachment as well as file from SharePoint

    Thanks, I get the emails fine with attachments.

    However, I still cannot open either the pdf nor the jpg files.

     

    Additional problem occurred again as mentioned before:

    When I take more than one photo to attach to the form, I get the two photos attached to the email which is correct but I also get two pdf files of the form which is unnecessary.
    I only need the filled pdf file once and then however many photo the person attached to the form which could be one or five or less or more.

  • v-litu-msft Profile Picture
    on 19 Oct 2020 at 07:51:49
    Re: Sending email with populated file attachment as well as file from SharePoint

    Hi @MSSAdmin,

     

    Thank you for your patience and explanation of the situation. 

    The error that Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The action(s) 'Create_file' referenced by 'inputs' in action 'Append_to_array_variable' are not defined in the template.'.' is caused by the action name not correct.

    I can see that you have renamed the Create file action, so the expression should be corrected to:

    {
     "Name": "@{outputs('Create_PDF_file')?['body/Name']}",
     "ContentBytes": "@{base64(outputs('Convert_Word_Document_to_PDF')?['body'])}"
    }

     

    The reason for the file has been damaged is caused by the send Email action only accept base64 format, so we should force the contents of the file to base64 code in case some file content isn't.

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • MSSAdmin Profile Picture
    44 on 19 Oct 2020 at 02:50:29
    Re: Sending email with populated file attachment as well as file from SharePoint

    I'm getting the following error message when doing that:
    Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The action(s) 'Create_file' referenced by 'inputs' in action 'Append_to_array_variable' are not defined in the template.'.'.

     

    Honestly I'm losing my mind over this whole thing. I have tried for several hours almost non-stop to find a solution and all I get is more problems.

    I have two flows that are the same, they just get content from two different form submissions in PowerApps/SharePoint. Therefore I copy/pasted one flow and adjusted what was needed for the other

    (i.e. SharePoint list name etc).

    However they both act differently.

    While one doesn't give me any attachments at all, the other one worked a few hours ago but with corrupt attachments and now I'm not even getting an email sent.

    This whole time though, the flow works fine. I don't get error messages, only the green "Your flow ran successfully".

    Screen Shot 2020-10-19 at 1.50.06 pm.png

  • v-litu-msft Profile Picture
    on 19 Oct 2020 at 02:41:43
    Re: Sending email with populated file attachment as well as file from SharePoint

    Hi @MSSAdmin,

     

    You could refer to my first reply, use the base64() function convert the file content into base64 code, and try it again:

    {
     "Name": "@{outputs('Create_file')?['body/Name']}",
     "ContentBytes": "@{base64(outputs('Convert_Word_Document_to_PDF')?['body'])}"
    }

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • MSSAdmin Profile Picture
    44 on 18 Oct 2020 at 22:17:27
    Re: Sending email with populated file attachment as well as file from SharePoint

    I have another question:

    When trying to attach more than 1 picture as an attachment, I get sent an email and there are two problems with it:

    1) I get sent the two pictures I attached (as it should) but also the filled in PDF twice.

    2) I can't open the pictures nor the pdfs that are attached.

    The error message for the pdf file is: 
    Adobe Acrobat Reader could not open 'Draft - Hrunf[2].pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).

     

    The error message for the photo is:
    The file “2E4B625D-218F-4615-AB41-DAC574185066[1].jpg” could not be opened. It may be damaged or use a file format that Preview doesn’t recognise.

     

    Any suggestions on why that happens?

     

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Loading complete