Aniruddhsingh Rathore
Aniruddhsingh Rathore

Reputation: 311

Separate attachment from Raw mime message from Sendgrid in Nodejs

I have a response coming from sendgrid inbound webhook, and it have some attachment, but is there any way we can separate the attachment from the full email payload.

This is the email body we receive from sendgrid below: I have shortened the email body and included important property including the X-Attachment-Id and right below is base64 attachment.

body = {
    dkim: '{@gmail.com : pass}',
    subject: 'Subject 1',
    email: 'Received: by mx0121p1iad2.sendgrid.net with SMTP id U3SN4cHg8C Wed, 21 Sep 
            2022 16:36:45 +0000 (UTC)\n' +
            '--000000000000de567405e9328c5d\n' +
            'Content-Type: application/pdf; name="dummy copy.pdf"\n' +
            'Content-Disposition: attachment; filename="dummy copy.pdf"\n' +
            'Content-Transfer-Encoding: base64\n' +
            'Content-ID: <f_l8buktdz0>\n' +
            'X-Attachment-Id: f_l8buktdz0\n' +
            '\n' +
            'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp\n' +
            'bHRlci9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nD2OywoCMQxF9/mKu3YRk7bp\n' +
            'tDAIDuh+oOAP+AAXgrOZ37etjmSTe3ISIljpDYGwwrKxRwrKGcsNlx1e31mt\n' +'\n' +
            '--000000000000de567405e9328c5d\n' }

I know I can use string methods to separate the part below the X-Attachment-ID property for making the attachment which is in base64 format, but is there any other way from sendgrid so we can separate any number of attachments.

Upvotes: 1

Views: 940

Answers (1)

lizziepika
lizziepika

Reputation: 3300

Twilio developer evangelist here.

This will most likely be resolved via code implementation with the Parse Webhook on the endpoint that you are consuming Parse payload information too.

This SO answer may be helpful.

Additionally, if you are not already, we do recommend that you select "POST the raw, full MIME message" in your Inbound Parse Settings under Settings > Inbound Parse in the SendGrid UI.

Let me know if this helps at all!

Upvotes: 0

Related Questions