Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Send HTTP POST with email attachment

(1) ShareShare
ReportReport
Posted on by 11

Hi, 

 

I'm currently trying to create a flow that is triggered when a new email is received and for each of the attachments creates an HTTP requests which posts the content to a backend server for further processing of the file.

 

I tried setting the file as content body and also as a request parameter' file. In all cases, I'm receiving that the file is Null at the backend.

I've also tried posting the array of attachments and I get a Json like this:

[{
	@odata.type = #Microsoft.OutlookServices.FileAttachment,
	Id = AQMkADNmNWYwMWViLT...,
	Name = myPhoto.jpg,
	ContentType = image / jpeg,
	Size = 19092,
	ContentBytes = null
}, {
	@odata.type = #Microsoft.OutlookServices.FileAttachment,
	Id = AQMkADNmNWYwMWViLTcx... ,
	Name = My PDF.pdf,
	ContentType = application / pdf,
	Size = 44972,
	ContentBytes = null
}]

The problem I have is that contentBytes is always null. If I try to loop trough each of the attachments and get the content, I post a null value in the request body.

 

What's the proper way to post an email attachment to an HTTP request?

  • KvB1 Profile Picture
    1,596 on at
    Re: Send HTTP POST with email attachment

    Hi ^^

     

    The content type is purely layout and has to do with the context of the automate. I needed the automate to fetch a specific mail, and have it in the body of the mail to be sent. Some emails are grabbed with a html layout, others are just text. If you would send the html layout as text, you lose the layout. The if statement is there to check if the fetched mail is html or text, in order to make the content type of the mail to be sent html or text.

     

    The file is from a sharepoint library. The $content is simply grabbing the actual content of the action of get file content

  • SH2021 Profile Picture
    89 on at
    Re: Send HTTP POST with email attachment

    Hi @KvB1 thanks for your reply.

    - Could you spell out what you have under "contentType"?
    - Does $content indicate that you are attaching documents that are attached to SharePoint list items (i.e. attachment of a specific row of a sharepoint list)?
    - I was trying to grab documents that are uploaded in a SharePoint File Folder.

    Groetjes 🙂

  • KvB1 Profile Picture
    1,596 on at
    Re: Send HTTP POST with email attachment

    This is what worked for me, tried different variations of syntax and also added "hasAttachments":"true"

    KvB1_1-1668179706183.png

     

     

  • SH2021 Profile Picture
    89 on at
    Re: Send HTTP POST with email attachment

    Nope 😞

  • KvB1 Profile Picture
    1,596 on at
    Re: Send HTTP POST with email attachment

    Did you manage to get it to work? Sorry to necro a thread, but it seems like a very useful bit of knowledge ^^

  • SH2021 Profile Picture
    89 on at
    Re: Send HTTP POST with email attachment

    Hi again. I am trying to solve my question from above over here. Please help if you know how this works 🙂
    https://powerusers.microsoft.com/t5/Building-Flows/Post-File-via-HTTP/m-p/1428038#M160358

  • SH2021 Profile Picture
    89 on at
    Re: Send HTTP POST with email attachment

    Dear Community

     

    I am facing this problem and I could not find a proper explanation. If anyone knows how to attach documents that are saved in SharePoint to an HTTP POST request used to create draft emails in Outlook, then please share this valuable piece of info!

     

    I want to obtain "test.pptx" which lies in a SharePoint document folder and then attach it to my HTTP POST request. I first import all the data from this folder and then loop through the data in it. When the loop is at the test.pptx file, I obtain the "id" by using the dynamic content "identifier", as well as the "Name" by using "File Name with Extension". Interestingly, "File Name with Extension" gave me the contentType when saving it in an array. 
    I furthermore load the data directly by using the identifier, which gives me the "ContentBytes" and I then get "Size" by using int(length(string(body('Dateiinhalt_abrufen')))) (its in German).

     

    Below is one of many trials. I'd appreciate any feedback! For example, is the positioning of the attachment correct, or should it appear somewhere else?


    Kind regards
    Sean

     

    {

      "subject": "attachment try ",
      "body":{
      "contentType":"HTML",
      "content":"Dear X, how are you doing? Bye, Y",},
      "toRecipients":[
      {
      "emailAddress":{
      "address":"me.me@me.com"}
      }
    ],
      "ccRecipients":[

      {
      "emailAddress":{
      "address":"me.me@me.com"}
      }
    ],
      [{
      "@odata.type": #Microsoft.OutlookServices.FileAttachment,
      "Id": "Shared%2bDocuments%252faktuelles%2bQuartal%252ftest_GH_.pptx" ,
      "Name": "test.pptx" ,
       "ContentType": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
      "Size": 32731,
      "ContentBytes": "UEsDBBQA…”
      }]

    }

     

    Error upon running:

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

  • Suhabavan Profile Picture
    6 on at
    Re: Send HTTP POST with email attachment

    Hi,

    I want to send an email with attachment. 

    My requirement 

    1. Want to send an attachment in the HTTP post using( When a HTTP request is received.)
    2. Extract the attachment from the URL and store the attachment in the variable
    3. Add the variable to the email attachment.
    4. Finally return Response after send the mail.

    I know how to send a normal email without attachment. But i want to send with attachment. Please help me !!

    @AlexRD Can you explain how you are sending an attachment using HTTP post request and adding the attachment to the email connector.

     

    Thanks in advance.

     

  • Verified answer
    AlexRD Profile Picture
    11 on at
    Re: Send HTTP POST with email attachment

    After serveral hours of debugging and crying in the corner, I just figured out what was wrong. I wasn't including the email attachments from the initial trigger action. Make sure to select "Include email attachment".

    The attachment is encoded in Base64.

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

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!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1