Send MMS

    You can send and receive MMS (media messages) in the United States and Canada by using a Plivo phone number that is MMS-enabled.

    In this guide, we’ll see how to use Plivo APIs to send MMS messages to Canada and US from your web application. Let’s have a look at some prerequisites before we dive into the code.

    • Plivo Auth Id and Auth Token: You will find your Plivo Auth Id and Auth Token on the home screen of your Plivo Console. Click here to sign-up for a Plivo account if you haven’t already!
    • Plivo Server-side SDK: The code in this tutorial uses Plivo’s Python Server-side SDK. To get started with the SDK in the language of your choice, visit the Server-side SDKs page.
    • Plivo Phone Number: Currently, Plivo offers MMS-enabled long code phone numbers in the US and Canada. You must have an MMS enabled valid Plivo phone number to send messages to the US and Canada. You can purchase MMS enabled numbers from the Numbers section of your Plivo Management Console. It is also possible to purchase numbers using the Numbers API.

    Sending MMS Using Plivo REST API

    This tutorial will show you how to send an outbound Multimedia Message Service (MMS) (i.e., picture message) using Plivo’s REST API. This can be used in any web or mobile application that requires communication with end users via MMS messages.

    MMS on Plivo offers full support for common image file types: png, jpeg, and gif and Unicode UTF-8 encoded texts, which means that you can send messages in any language. Delivery reports are also automatically supported in networks where they are provided by the operator.

    To send an MMS, we’ll need to make an HTTP POST request to the Message API.

    POST https://api.plivo.com/v1/Account/{auth_id}/Message/

    Getting Started

    1. Sign up for a Plivo trial account.
    2. Check out our server-side SDKs page and install the right helper based on the programming language you want to use.
    3. Buy an MMS enabled Plivo phone number . You can buy a US or Canadian MMS enabled phone number through the Buy Numbers tab on your Plivo account UI.
    4. Use a web hosting service to host your web application. There are many inexpensive cloud hosting providers that you can use for just a few dollars a month. Follow the instructions of your hosting provider to host your web application.
      Note: If you are using a Plivo Trial account for this example, you can only send mms to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.

    Implementation

    1. Copy the relevant code below into a text file and save it.
    2. Replace Your AUTH_ID and Your AUTH_TOKEN with the AUTH ID and AUTH TOKEN found on your Plivo Console.
    3. Add your 'src' (source) phone number. This will show up as your Sender ID.
      Note:In order to send MMS messages to phones in the US or Canada, you will need to purchase a US or Canadian phone number from Plivo which is MMS enabled and use it as the 'src' number. You can buy a Plivo number from the Buy Numbers tab on your Plivo Console. Be sure that the phone number is in E.164 format (e.g., +14153336666).
    4. Add your 'dst' (destination) phone numbers. This is the phone number you will be sending MMS messages to. Be sure that the phone number is in E.164 format (e.g., +15671234567).
      Note: If you are using a trial account, your destination number needs to be verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.
    5. Edit the 'text' field with your text message.
    6. Set Type as MMS. This field is optional for sending SMS and mandatory for sending MMS.
    7. Add the media to be sent via MMS through mediaURLs parameter. This field is optional for sending SMS and mandatory for sending MMS.
    8. Make the 'HTTP POST' request to Plivo. If successful, Plivo will queue your MMS and deliver it to your recipients at a base rate of 1 message per second. \
    Advanced Hack: Check out our full Message API docs to see all the parameters and functionalities you can use.

    Code

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    import plivo
    
    client = plivo.RestClient("auth_id","auth_token")
    
    response = client.messages.create(
         src='+14845355113',
         dst='+14845780436',
         media_urls=["https://media0.giphy.com/media/cmwNV9sYalHK3twjsf/giphy.gif?cid=790b7611241311531367a66f916c7ce5199d4aa61812adbf&rid=giphy.gif","https://www.cbronline.com/wp-content/uploads/2016/06/what-is-URL-770x503.jpg"],
         type_='mms',
     )
    print(response)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    require 'rubygems'
    require 'plivo'
    
    include Plivo
    include Plivo::Exceptions
    
    api = RestClient.new("auth_id", "auth_token")
    
    begin
    response = api.messages.create(
        '+14845355114',
        ['+14845780436'],
        'message',
        { url: "http://foo.com/sms_status/",
          method: "POST",
          log: false,
          trackable: true,
          media_urls:["http://foo.com/sms_status/"],
          type: "mms"
        }
    )
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    let plivo = require('plivo');
    let client = new plivo.Client('auth_id', 'auth_token');
    
    let optionalParams = {};
    client.messages.create(
     "+14845355114", //src
     "+14845780436", // dst
     "Hello, this is a sample text from Plivo", // text
     {
       type: "mms",
       method: "GET",
       url: "http://foo.com/sms_status/",
       media_urls: ["https://media0.giphy.com/media/cmwNV9sYalHK3twjsf/giphy.gif?cid=790b7611241311531367a66f916c7ce5199d4aa61812adbf&rid=giphy.gif", "https://www.cbronline.com/wp-content/uploads/2016/06/what-is-URL-770x503.jpg"]
     }
    
    ).then(function (message_created) {
     console.log(message_created)
    }).catch(function (error) {
     console.log(error);
    });
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    <?php
    require 'vendor/autoload.php';
    use Plivo\RestClient;
    
    $client = new RestClient("auth_id", "auth_token");
    
    $mediaURLs = ['https://media0.giphy.com/media/cmwNV9sYalHK3twjsf/giphy.gif?cid=790b7611241311531367a66f916c7ce5199d4aa61812adbf&rid=giphy.gif', 'https://www.cbronline.com/wp-content/uploads/2016/06/what-is-URL-770x503.jpg'];
    $response = $client->messages->create(
        '+14845355113', #from
        ['+14845780436'], #to
        null,
        ['type'=>'mms', 
        'media_urls'=>$mediaURLs
        ]
    );
    ?>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    
    import java.io.IOException;
    import java.net.URL;
    import java.util.Collections;
    
    import com.plivo.api.Plivo;
    import com.plivo.api.exceptions.PlivoRestException;
    import com.plivo.api.models.message.Message;
    import com.plivo.api.models.message.MessageCreateResponse;
    
    public class Test {
        public static void main(String[] args) {
          Plivo.init("auth_id", "auth_token");
    
          try {
            MessageCreateResponse response = Message.creator("+14845355114",Collections.singletonList("+14845780436"),
              "Hello, this is test message").type(MessageType.MMS).media_urls(new String[]{"https://www.cbronline.com/wp-content/uploads/2016/06/what-is-URL-770x503.jpg"})
              .create();
            System.out.println(response);
            // Prints only the message_uuid
            System.out.println(response.getMessageUuid());
            }
       
          catch (  PlivoRestException | IOException e ) {
            e.printStackTrace();
            }
        }
    }
       
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    package main
    
    import "fmt"
    import "github.com/plivo/plivo-go"
    
    func main() {
        client, err := plivo.NewClient("auth_id", "auth_token", &plivo.ClientOptions{}
        if err != nil {
            panic(err)
        }
    	resp, err := client.Messages.Create(plivo.MessageCreateParams{
    		Src: "+14845355114",
    		Dst :"+14845780436",
    		Type:"mms",
    		MediaUrls: []string{"https://media.giphy.com/media/lhvyCCcFuQFKo/giphy.gif"},
        })
        if err != nil {
            panic(err)
        }
    	fmt.Printf("Response: %#v\n", resp.Message)
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    using System;
    using System.Collections.Generic;
    using Plivo;
    
    namespace PlivoExamples
    {
        internal class Program
        {
            public static void Main(string[] args)
            {
                var api = new PlivoApi("auth_id", "auth_token");
                var response = api.Message.Create(
                    dst:new List<String>{"+19494245111"},
                    text:"Test Message",
                    src:"+14845355114",
                    url:"",
                    log:false,
                    trackable:false,
                    method:"GET",
                    type:"mms",
                    media_urls:new string[] { "https://i.redd.it/wf9j4r09yir31.jpg" }
                );
                Console.WriteLine(response);
            }
        }
    }
    
    1
    2
    3
    4
    
    curl -i --user auth_id:auth_token \
        -H "Content-Type: application/json" \
        -d '{"src": "your_src_number","dst": "+14152223333", "text": "Hello, this is test message","type":"mms","media_urls":["http://www.pdf995.com/samples/pdf.pdf"], "url":"http://foo.com/sms_status/"}' \
        https://api.plivo.com/v1/Account/{auth_id}/Message/