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:
| Key | Description |
|---|---|
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 |
VONAGE_FROM_NUMBER | Refer to |
TO_NUMBER | The number you are sending the to in E.164 format. For example |
IMAGE_URL | The URL of the media you want to send. Accepted file formats are |
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"
}'
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
npm install @vonage/server-sdkCreate a file named send-mms.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const { MMSImage } = require('@vonage/messages');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Write the code
Add the following to send-mms.js:
vonage.messages.send(
new MMSImage({
image: {
url: IMAGE_URL,
},
to: TO_NUMBER,
from: FROM_NUMBER,
}),
)
.then(({ messageUUID}) => console.log(messageUUID))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
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:1.1.2'Create a file named SendMmsImage and add the following code to the main method:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
}Write the code
Add the following to the main method of the SendMmsImage file:
val messageId = client.messages.send(
mmsImage {
to(TO_NUMBER)
from(VONAGE_FROM_NUMBER)
url(IMAGE_URL)
caption(IMAGE_CAPTION)
}
)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:
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:8.15.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();Write the code
Add the following to the main method of the SendMmsImage file:
var response = client.getMessagesClient().sendMessage(
MmsImageRequest.builder()
.from(FROM_NUMBER).to(TO_NUMBER)
.url(IMAGE_URL)
.build()
);
System.out.println("Message sent successfully. ID: "+response.getMessageUuid());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:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Install-Package VonageWrite the code
Add the following to SendMmsImage.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(appId, privateKeyPath);
var vonageClient = new VonageClient(credentials);
var request = new Vonage.Messages.Mms.MmsImageRequest
{
To = to,
From = brandName,
Image = new Attachment
{
Url = "https://example.com/image.jpg"
}
};
var response = await vonageClient.MessagesClient.SendAsync(request);Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
composer require vonage/clientCreate 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);Write the code
Add the following to send-mms.php:
$image = new \Vonage\Messages\MessageObjects\ImageObject(
'https://example.com/image.jpg',
'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);Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
pip install vonageWrite the code
Add the following to send-image.py:
from vonage import Auth, Vonage
from vonage_messages.models import MmsImage, MmsResource
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)
message = MmsImage(
to=TO_NUMBER,
from_=FROM_NUMBER,
image=MmsResource(url=IMAGE_URL),
)
response = client.messages.send(message)
print(response)Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
gem install vonageCreate a file named send-mms.rb and add the following code:
client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)Write the code
Add the following to send-mms.rb:
message = Vonage::Messaging::Message.mms(
type: 'image',
message: {
url: "https://example.com/image.jpg",
caption: "A MMS image message, with caption, sent using the Vonage Messages API"
}
)
client.messaging.send(
from: VONAGE_FROM_NUMBER,
to: TO_NUMBER,
**message
)Run your code
Save this file to your machine and run it:
Try it out
When you run the code an MMS message is sent to the destination number.