Send an MMS

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

IMPORTANT: Only US short codes, 10DLC numbers and SMS Enabled Toll Free Numbers are currently supported for sending MMS. For US short codes, 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).

Message throughput, deliverability, and SMS message volumes may vary depending on the type of number used. For more information on this, and on MMS in general, see the Vonage MMS overview page, the Vonage 10DLC overview page, and the Vonage Phone Numbers overview page.

Example

Find the description for all variables used in each code snippet below:

KeyDescription
VONAGE_APPLICATION_ID

The Vonage Application ID.

VONAGE_APPLICATION_PRIVATE_KEY_PATH

Private key path.

VONAGE_PRIVATE_KEY_PATH

Private key path.

FROM_NUMBER

The phone number you are sending the MMS from. (US Short Code, 10DLC number, or SMS Enabled Toll Free Number)

VONAGE_NUMBER

Refer to FROM_NUMBER above

VONAGE_FROM_NUMBER

Refer to FROM_NUMBER above

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 "${MESSAGES_API_URL}" \
  -H "Authorization: Bearer "$JWT\
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{
    "to": "'${MESSAGES_TO_NUMBER}'",
    "from": "'${MMS_SENDER_ID}'",
    "channel": "mms",
    "message_type": "image",
    "image": {
      "url": "'${MESSAGES_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 @vonage/messages

Create a file named send-mms.js and add the following code:

const { Vonage } = require('@vonage/server-sdk');
const { Channels } = require('@vonage/messages');

/**
 * It is best to send messages using JWT instead of basic auth. If you leave out
 * apiKey and apiSecret, the messages SDK will send requests using JWT tokens
 *
 * @link https://developer.vonage.com/en/messages/technical-details#authentication
 */
const vonage = new Vonage(
  {
    applicationId: VONAGE_APPLICATION_ID,
    privateKey: VONAGE_PRIVATE_KEY,
  },
  {
    ...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}),
  },
);

View full source

Write the code

Add the following to send-mms.js:

vonage.messages.send({
  messageType: 'image',
  channel: Channels.MMS,
  image: {
    url: MESSAGES_IMAGE_URL,
  },
  to: MESSAGES_TO_NUMBER,
  from: MMS_SENDER_ID,
})
  .then(({ messageUUID }) => console.log(messageUUID))
  .catch((error) => console.error(error));

View full source

Run your code

Save this file to your machine and run it:

node send-mms.js

Prerequisites

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

Add the following to build.gradle:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'

Create a file named SendMmsImage and add the following code to the main method:

val client = Vonage {
    applicationId(VONAGE_APPLICATION_ID)
    privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}

View full source

Write the code

Add the following to the main method of the SendMmsImage file:

val messageId = client.messages.send(
    mmsImage {
        to(MESSAGES_TO_NUMBER)
        from(MMS_SENDER_ID)
        url(MESSAGES_IMAGE_URL)
        caption(MESSAGES_CAPTION)
    }
)

View full source

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.messages.mms with the package containing SendMmsImage:

gradle run -Pmain=com.vonage.quickstart.kt.messages.mms.SendMmsImage

Prerequisites

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

Add the following to build.gradle:

implementation 'com.vonage:server-sdk:9.3.1'

Create a file named SendMmsImage and add the following code to the main method:

VonageClient client = VonageClient.builder()
		.applicationId(VONAGE_APPLICATION_ID)
		.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
		.build();

View full source

Write the code

Add the following to the main method of the SendMmsImage file:

var response = client.getMessagesClient().sendMessage(
		MmsImageRequest.builder()
			.from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER)
			.url(MESSAGES_IMAGE_URL)
			.build()
);
System.out.println("Message sent successfully. ID: "+response.getMessageUuid());

View full source

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.vonage.quickstart.messages.mms with the package containing SendMmsImage:

gradle run -Pmain=com.vonage.quickstart.messages.mms.SendMmsImage

Prerequisites

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

Install-Package Vonage

Write the code

Add the following to SendMmsImage.cs:

var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);

var vonageClient = new VonageClient(credentials);

var request = new Vonage.Messages.Mms.MmsImageRequest
{
    To = MESSAGES_TO_NUMBER,
    From = MMS_SENDER_ID,
    Image = new Attachment
    {
        Url = MESSAGES_IMAGE_URL
    }
};

var response = await vonageClient.MessagesClient.SendAsync(request);

View full source

Prerequisites

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

composer require vonage/client

Create a file named send-mms.php and add the following code:

$keypair = new \Vonage\Client\Credentials\Keypair(
    file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
    VONAGE_APPLICATION_ID
);

$client = new \Vonage\Client($keypair);

View full source

Write the code

Add the following to send-mms.php:

$image = new \Vonage\Messages\MessageObjects\ImageObject(
    MESSAGES_IMAGE_URL,
    'A MMS image message, with caption, sent using the Vonage Messages API'
);

$mms = new \Vonage\Messages\Channel\MMS\MMSImage(
    TO_NUMBER,
    FROM_NUMBER,
    $image
);

$client->messages()->send($mms);

View full source

Run your code

Save this file to your machine and run it:

php send-mms.php

Prerequisites

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

pip install vonage python-dotenv

Write the code

Add the following to send-image.py:

from vonage import Auth, Vonage
from vonage_messages import MmsImage, MmsResource

client = Vonage(
    Auth(
        application_id=VONAGE_APPLICATION_ID,
        private_key=VONAGE_PRIVATE_KEY,
    )
)

message = MmsImage(
    to=MESSAGES_TO_NUMBER,
    from_=MMS_SENDER_ID,
    image=MmsResource(url=MESSAGES_IMAGE_URL),
)

response = client.messages.send(message)
print(response)

View full source

Run your code

Save this file to your machine and run it:

python messages/mms/send-image.py

Prerequisites

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

gem install vonage

Create a file named send-mms.rb and add the following code:

client = Vonage::Client.new(
  application_id: VONAGE_APPLICATION_ID,
  private_key: VONAGE_PRIVATE_KEY
)

View full source

Write the code

Add the following to send-mms.rb:

message = client.messaging.mms(
  type: 'image',
  message: {
    url: MESSAGES_IMAGE_URL
  }
)

client.messaging.send(
  from: MMS_SENDER_ID,
  to: MESSAGES_TO_NUMBER,
  **message
)

View full source

Run your code

Save this file to your machine and run it:

ruby send-mms.rb

Try it out

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