Send an MMS Text Message

In this code snippet you will see how to send an MMS text message 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
MESSAGES_API_URL

There are two versions of the API, each with their own endpoints. For production the previous Messages API endpoint was https://api.nexmo.com/v0.1/messages, the new one is https://api.nexmo.com/v1/messages. For sandbox testing the Messages API endpoint is https://messages-sandbox.nexmo.com/v0.1/messages or https://messages-sandbox.nexmo.com/v1/messages, depending on which version you have set in the sandbox dashboard.

MESSAGES_TO_NUMBER

The number you are sending the to in E.164 format. For example 447700900000.

MMS_SENDER_ID

The alphanumeric string that represents the name or number of the organization sending the message.

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-text.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": "text",
    "text": "This is an MMS text message sent via the Vonage Messages API."
  }'

View full source

Run your code

Save this file to your machine and run it:

bash send-mms-text.sh

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 SendMmsText 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 SendMmsText file:

val messageId = client.messages.send(
    mmsText {
        to(MESSAGES_TO_NUMBER)
        from(MMS_SENDER_ID)
        text("This is an MMS text message sent using the Messages API")
    }
)

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 SendMmsText:

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

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 SendMmsText 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 SendMmsText file:

var response = client.getMessagesClient().sendMessage(
		MmsTextRequest.builder()
			.from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER)
			.text("This is an MMS message with text")
			.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 SendMmsText:

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

Try it out

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