Send an MMS

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

IMPORTANT: Only US Short codes are currently supported for sending MMS.

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/v0.1/messages \
  -H 'Authorization: Bearer '$JWT\
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{ 
   "from":{
        "type": "mms",    
        "number": "$FROM_NUMBER"
   },
   "to":{
        "type": "mms",
        "number": "$TO_NUMBER"
   },
   "message":{ 
      "content":{
          "type": "image",
          "image": {
              "url": "$IMAGE_URL"
          }
      }
   }
}'

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.