cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AlexRD
New Member

Send HTTP POST with email attachment

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?

1 ACCEPTED SOLUTION

Accepted Solutions
AlexRD
New Member

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.

View solution in original post

9 REPLIES 9
AlexRD
New Member

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.

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.

 

SH2021
Advocate I
Advocate I

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.

SH2021
Advocate I
Advocate I

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

KvB1
Solution Sage
Solution Sage

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

SH2021
Advocate I
Advocate I

Nope 😞

KvB1
Solution Sage
Solution Sage

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

KvB1_1-1668179706183.png

 

 

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
Solution Sage
Solution Sage

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

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (3,448)