Email Attachments and Inline Images

In order to send email messages with attachments or inline images, you must first upload them into Messaging API. It is mandatory to provide the Content-Type in the HTTP headers, and also chucked transmission is not supported yet.

POST https://messaging.messagebird.com/v1/files

Here's a sample request of how can you upload a file to Messaging API.

curl -X POST https://messaging.messagebird.com/v1/files -H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' -H 'Content-Disposition: attachment; filename="testing_image.png"' -H 'Content-Type: image/png' --data-binary @input_image.png

The HTTP response will look like the following.

{
"id": "ebf6acee-d7ae-4375-b726-e247318d3377",
}

The HTTP response contains the media ID, which can be used when sending the email message through Conversations API.

Here's an example of sending an email message with an attachment. Note that the media ID must be provided in the field content.email.attachments.id.

curl -X "POST" "https://conversations.messagebird.com/v1/send" \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"content": {
"email": {
"attachments": [
{
"id": "742599bd-1a46-42b4-b382-114f9b4fb54e"
}
],
"subject": "Sample message with attachment",
"to": [
{
"name": "John Doe",
"address": "john.doe@sample.com"
}
],
"content": {
"html": "Hello! Here is a sample message with attachment."
},
"from": {
"name": "Customer Support",
"address": "support@yourcompany.com"
}
}
},
"to": "john.doe@sample.com",
"type": "email",
"from": "452859f5f5734db8808753acg4f49908"
}'

Here's an example of sending an email message with an inline image. Please note that:

  • The media ID must be provided in the field content.email.inlineImages.id
  • Every inline image must have a contentID (content.email.inlineImages.contentID). The contentID must be used in the src property of the image tag within the message content (content.email.content.html): <img src="cid:mb-logo">.
curl -X "POST" "https://conversations.messagebird.com/v1/send" \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"content": {
"email": {
"subject": "Sample message with inline image",
"to": [
{
"name": "John Doe",
"address": "john.doe@sample.com"
}
],
"content": {
"html": "<p>Hello! Here is a sample message with an inline image:</p><img src=\\"cid:mb-logo\\">"
},
"inlineImages": [
{
"id": "742599bd-1a46-42b4-b382-114f9b4fb54e",
"contentID": "mb-logo"
}
],
"from": {
"name": "Customer Support",
"address": "support@yourcompany.com"
}
}
},
"to": "john.doe@sample.com",
"type": "email",
"from": "452859f5f5734db8808753acg4f49908"
}'

In case you need to fetch the media in Messaging API, you can do it by using the following endpoint.

GET https://messaging.messagebird.com/v1/files/{id}

Here is a sample request you can use to fetch a specific file from Messaging API.

curl -X GET https://messaging.messagebird.com/v1/files/ebf6acee-d7ae-4375-b726-e247318d3377
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM'
--output uploaded_image.png
Next upIp Warmup

Questions?

We’re always happy to help with code or other doubts you might have! Check out our Quickstarts, API Reference, Tutorials, SDKs, or contact our Support team.

Cookie Settings