William Hawkins
William Hawkins

Reputation: 1

How to embed image in email message using curl interface to SendGrid

I am trying to use the curl interface to SendGrid to send an email with an embedded image (not an attachment) and cannot work out the correct syntax. I am also on Windows, so the issues with the json quotes and the windows command line mean I have to create a file and use the curl -d option.

Here's my curl command:

curl --url https://api.sendgrid.com/v3/mail/send --request POST \
    --header "Authorization: Bearer mybearertokenstring " \
    --header "Content-Type: application/json" \
    -d "@E:\temp\curl_RCC_20240506104528.tmp"

Here's my temp file contents:

{"personalizations": [{"to": [{"email": "[email protected]"}]}], "from": {"email": "[email protected]"}, "subject": "folio number", "content": [{"type": "text/html", "value": "<html><body>Image file = E:/images/allproplogo.jpg<br><img height="326" width="620" id="Picture 2" class="center" src="cid:image0001" /></body></html>"}] ,"files": [{"filename":"allproplogo.jpg", "type": "image/jpeg", "cid":"image0001", "content":"base64encodedimage"}]}

In response, I get this error message

{"errors":[{"message":"Bad Request","field":null,"help":null}]}

I have tried various combinations of base64 encrypting the message, but I either get this message or a bad UTF8 response.

Upvotes: 0

Views: 105

Answers (1)

Ladson Mario
Ladson Mario

Reputation: 9

A solution to this would be to upload your image to some service, get its public URL and insert it into an .html file in the src="" of the <img /> tag.

Upvotes: 0

Related Questions