Send an MMS

In this code snippet you will see how to send an MMS using the Messages API.

IMPORTANT: Only US short codes and 10DLC numbers are currently supported for sending MMS. For 10DLC, MMS messages can be sent to AT&T, T-Mobile (previously Sprint), and Verizon networks in the US. Find out more about setting up 10DLC numbers (note: this page references the SMS API, but the contents of the 10 DLC guidelines section also apply to the Messages API).

Some advantages of using 10DLC include higher message throughput, better deliverability, and higher SMS message volumes. See the Vonage 10DLC overview for more information.

Example

Ensure the following variables are set to your required values using any convenient method:

Key Description
FROM_NUMBER The phone number you are sending the MMS from. (US Short Code only)
TO_NUMBER The number you are sending the to in E.164 format. For example 447700900000.
IMAGE_URL The URL of the media you want to send. Accepted file formats are .jpg, .jpeg, .png, and .gif.

NOTE: Don't use a leading + or 00 when entering a phone number, start with the country code, for example 14155550105.

Prerequisites

If you do not have an application you can create one. Make sure you also configure your webhooks.

Write the code

Add the following to send-mms.sh:

curl -X POST https://api.nexmo.com/v1/messages \
  -H 'Authorization: Bearer '$JWT\
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{
            "message_type": "image",
            "image": {
                "url": "https://example.com/image.jpg"
            },
            "to": "$TO_NUMBER",
            "from": "$FROM_NUMBER",
            "channel": "mms"
}'

View full source

Run your code

Save this file to your machine and run it:

bash send-mms.sh

Prerequisites

If you do not have an application you can create one. Make sure you also configure your webhooks.

npm install @vonage/server-sdk@beta

Write the code

Add the following to send-mms.js:

const Vonage = require('@vonage/server-sdk')

const vonage = new Vonage({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET,
  applicationId: VONAGE_APPLICATION_ID,
  privateKey: VONAGE_APPLICATION_PRIVATE_KEY_PATH
})

vonage.channel.send(
  { "type": "mms", "number": TO_NUMBER },
  { "type": "mms", "number": FROM_NUMBER },
  {
    "content": {
      "type": "image",
       "image": { "url": IMAGE_URL }
    }
  },
  (err, data) => {
    if (err) {
      console.error(err);
    } else {
      console.log(data.message_uuid);
    }
  }
);

View full source

Run your code

Save this file to your machine and run it:

node send-mms.js

Try it out

When you run the code an MMS message is sent to the destination number.