0

I have configured SendGrid Inbound Parse webhook to get email content on my AWS API endpoint.

So I am getting email content in multipart/form-data format but in string which contains \n\r.

AWS API event.body= --xYzZY\r\nContent-Disposition: form-data; name="dkim"\r\n\r\n{@perficient.onmicrosoft.com : pass}\r\n--xYzZY\r\nContent-Disposition: form-data; name="subject"\r\n\r\nFW: Test email

I want to extract fields like FROM, TO, Subject, Body, Attachment technology using NodeJS

After replacing \n\r with \n & process body with structured multipart form data getting following error

{ "errorType": "Error", "errorMessage": "Unexpected end of multipart data", "stack": [ "Error: Unexpected end of multipart data", " at /var/task/node_modules/dicer/lib/Dicer.js:61:28", " at process._tickCallback (internal/process/next_tick.js:61:11)" ] } 
mukund patel
  • 1,039
  • 10
  • 31

1 Answers1

0

Suggest using a node library like formidable to do all the hard work of parsing multipart/form-data for you. This will likely avoid the problem in the first place.

Matthew
  • 947
  • 2
  • 13
  • 20