Sending Messages

Sending an SMS or MMS is one of the most common tasks performed on the Twilio Platform. Sending a message is as simple as POSTing to the Messages resource. We'll outline required and optional parameters, messaging services, alphanumeric sender ID, rate limiting, and handling message replies below.

HTTP POST to Messages

To send a new outgoing message, make an HTTP POST to your Messages list resource URI:

/2010-04-01/Accounts/{AccountSid}/Messages

POST Parameters

Required Parameters

The To parameter is required in your POST to send the message:

Parameter Description
To The destination phone number. Format with a '+' and country code e.g., +16175551212 (E.164 format).

If you are sending messages while in trial mode, the 'To' phone number must be verified with Twilio. You can verify your phone number by adding it to your Verified Caller IDs in the console.

Send a Message with an Image URL

Send a message with a quote and image from a popular movie. Note that while you can send text-only messages just about anywhere on the planet, sending images is currently only possible in the US and Canada:

Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
Response Format:
  • json
  • xml
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.messages.create({
    body: "Jenny please?! I love you <3",
    to: "+15558675309",
    from: "+14158141829",
    mediaUrl: "http://www.example.com/hearts.png"
}, function(err, message) {
    process.stdout.write(message.sid);
});
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.messages.create({
  body: 'Jenny please?! I love you <3',
  to: '+15558675309',
  from: '+14158141829',
  mediaUrl: 'http://www.example.com/hearts.png',
})
.then((message) => process.stdout.write(message.sid));
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    
    var message = twilio.SendMessage("+14158141829", "+15558675309", "Jenny please?! I love you <3", new string[] {"http://www.example.com/hearts.png"});
    
    Console.WriteLine(message.Sid);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$client->account->messages->sendMessage("+14158141829", "+15558675309", "Jenny please?! I love you <3", "http://www.example.com/hearts.png");
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

message = @client.account.messages.create(
  :body => "Jenny please?! I love you <3",
  :to => "+15558675309",
  :from => "+14158141829",
  :media_url => "http://www.example.com/hearts.png")
puts message.to
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using System.Collections.Generic;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var mediaUrl = new List<Uri>() {
            new Uri("http://www.example.com/hearts.png")
        };
        var to = new PhoneNumber("+14158141829");
        var message = MessageResource.Create(to,
                                             from: new PhoneNumber("+15558675309"),
                                             body: "Jenny please?! I love you <3",
                                             mediaUrl: mediaUrl);

        Console.WriteLine(message.Sid);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$client->messages
    ->create(
        "+15558675309",
        array(
            "from" => "+14158141829",
            "body" => "Jenny please?! I love you <3",
            "mediaUrl" => "http://www.example.com/hearts.png"
        )
    );
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

message = client.messages.create(body="Jenny please?! I love you <3",
    to="+15558675309",
    from_="+14158141829",
    media_url="http://www.example.com/hearts.png")
print(message.sid)
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
require 'twilio-ruby'

# put your own credentials here
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new(account_sid, auth_token)

message = @client.account.messages.create(
  body: 'Jenny please?! I love you <3',
  to: '+15558675309',
  from: '+14158141829',
  media_url: 'http://www.example.com/hearts.png'
)

puts message.to
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.MessageFactory;
import com.twilio.sdk.resource.instance.Message;
import com.twilio.sdk.resource.list.MessageList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the MessageList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Body", "Jenny please?! I love you <3"));
    params.add(new BasicNameValuePair("To", "+15558675309"));
    params.add(new BasicNameValuePair("From", "+14158141829"));
    params.add(new BasicNameValuePair("MediaUrl", "http://www.example.com/hearts.png"));
    
    
    MessageFactory messageFactory = client.getAccount().getMessageFactory();
    Message message = messageFactory.create(params);
    System.out.println(message.getSid());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

message = client.messages.create(
        "+15558675309",
        body="Jenny please?! I love you <3",
        from_="+14158141829",
        media_url="http://www.example.com/hearts.png")

print(message.sid)
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

public class Example {
  /// Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Message message = Message
        .creator(new PhoneNumber("+15558675309"), new PhoneNumber("+14158141829"),
            "Jenny please?! I love you <3")
        .setMediaUrl("http://www.example.com/hearts.png")
        .create();

    System.out.println(message.getSid());
  }
}
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages \
    -d "Body=Jenny%20please%3F%21%20I%20love%20you%20<3" \
    -d "To=%2B15558675309" \
    -d "From=%2B14158141829" \
    -d "MediaUrl=http://www.example.com/hearts.png" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
    -d "Body=Jenny%20please%3F%21%20I%20love%20you%20<3" \
    -d "To=%2B15558675309" \
    -d "From=%2B14158141829" \
    -d "MediaUrl=http://www.example.com/hearts.png" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
   "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
   "api_version": "2010-04-01",
   "body": "Jenny please?! I love you <3",
   "num_segments": "1",
   "num_media": "1",
   "date_created": "Wed, 18 Aug 2010 20:01:40 +0000",
   "date_sent": null,
   "date_updated": "Wed, 18 Aug 2010 20:01:40 +0000",
   "direction": "outbound-api",
   "error_code": null,
   "error_message": null,
   "from": "+14158141829",
   "price": null,
   "sid": "MM90c6fc909d8504d45ecdb3a3d5b3556e",
   "status": "queued",
   "to": "+15558675309",
   "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MM90c6fc909d8504d45ecdb3a3d5b3556e.json"
}
<TwilioResponse>
	<Message>
		<Sid>MM90c6fc909d8504d45ecdb3a3d5b3556e</Sid>
		<DateCreated>Wed, 18 Aug 2010 20:01:40 +0000</DateCreated>
		<DateUpdated>Wed, 18 Aug 2010 20:01:40 +0000</DateUpdated>
		<DateSent/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<From>+14159352345</From>
		<To>+15558675309</To>
		<Body>Jenny please?! I love you &lt;3</Body>
        <NumSegments>1</NumSegments>
        <NumMedia>1</NumMedia>
		<Status>queued</Status>
		<Direction>outbound-api</Direction>
		<ApiVersion>2010-04-01</ApiVersion>
		<Price/>
		<PriceUnit>/>
		<ErrorCode/>
		<ErrorMessage/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MM90c6fc909d8504d45ecdb3a3d5b3556e</Uri>
	</Message>
</TwilioResponse>
Send a message with an image URL

Conditional Parameters

You must POST at least one of the following parameters to determine the 'From' phone number or Sender ID of your message:

Parameter Description
From A Twilio phone number (in E.164 format) or alphanumeric sender ID enabled for the type of message you wish to send. Phone numbers or short codes purchased from Twilio work here. You cannot (for example) spoof messages from your own cell phone number.
MessagingServiceSid The 34 character unique id of the Messaging Service you want to associate with this Message. Set this parameter to use the Messaging Service Settings and Copilot Features you have configured. When only this parameter is set, Twilio will use your enabled Copilot Features to select the From phone number for delivery.

There is a slight difference in API response when specifying the MessagingServiceSid parameter. When you only specify the From parameter, Twilio will validate the phone numbers synchronously and return either a queued status or an error. When specifying the MessagingServiceSid parameter, Twilio will first return an accepted status. Twilio then determines the optimal From phone number and any delivery errors will be sent asynchronously to your StatusCallback URL.

You must also POST at least one of the following parameters for the content of your message:

Parameter Description
Body The text of the message you want to send, limited to 1600 characters.
MediaUrl The URL of the media you wish to send out with the message. gif , png and jpeg content is currently supported and will be formatted correctly on the recipient's device. Other types are also accepted by the API. The media size limit is 5MB. If you wish to send more than one image in the message body, please provide multiple MediaUrls values in the POST request. You may include up to 10 MediaUrls per message.

If you are sending non-BMP characters in the message Body the number of characters could be smaller than 1600. Almost all global languages are supported without the use of the non-BMP character plane.

Note that if you do not specify a MediaUrl and the body is greater than 160 GSM-7 characters (or 70 UCS-2characters), the message will be sent as SMS, segmented and charged accordingly.

Content types for MediaUrl validation are fetched via the content-type header at the provided URLs. If the content-type header does not match the media, Twilio will reject the request. Twilio supports image/gif, image/png, and image/jpeg mime-types and accepts many others.

Optional Parameters

You may include the following parameters:

Parameter Description
StatusCallback A URL where Twilio will POST each time your message status changes to one of the following: queued, failed, sent, delivered, or undelivered. Twilio will POST the MessageSid along with the other standard request parameters as well as MessageStatus and ErrorCode. If this parameter passed in addition to a MessagingServiceSid, Twilio will override the Status Callback URL of the Messaging Service. URLs must contain a valid hostname (underscores are not allowed).
ApplicationSid Twilio will POST MessageSid as well as MessageStatus=sent or MessageStatus=failed to the URL in the MessageStatusCallback property of this Application. If the StatusCallback parameter above is also passed, the Application's MessageStatusCallback parameter will take precedence.
MaxPrice The total maximum price up to the fourth decimal (0.0001) in US dollars acceptable for the message to be delivered. All messages regardless of the price point will be queued for delivery. A POST request will later be made to your Status Callback URL with a status change of 'Sent' or 'Failed'. When the price of the message is above this value the message will fail and not be sent. When MaxPrice is not set, all prices for the message is accepted.
ProvideFeedback Set this value to true if you are sending messages that have a trackable user action and you intend to confirm delivery of the message using the Message Feedback API. This parameter is set to false by default.
ValidityPeriod The number of seconds that the message can remain in a Twilio queue. After exceeding this time limit, the message will fail and a POST request will later be made to your Status Callback URL. Valid values are between 1 and 14400 seconds (the default). Please note that Twilio cannot guarantee that a message will not be queued by the carrier after they accept the message. We do not recommend setting validity periods of less than 5 seconds.

Request Parameters

The parameters Twilio passes to your application in its request to the StatusCallback URL include all the standard request parameters and these additional parameters:

Parameter Description
MessageStatus The status of the message. Message delivery information is reflected in message status. The possible values are listed in the Message resource
ErrorCode The error code (if any) associated with your message. If your message status is failed or undelivered, the ErrorCode can give you more information about the failure. If the message was delivered successfully, no ErrorCode will be present. Find the possible values in the Message resource.

Messaging Services

As you use Twilio Messaging to power different use cases, it may be helpful to organize your account and message logs into separate Messaging Services. Messaging Services allow you to organize your messages and enable specific features for these groups of messages. This keeps your code clean and lets you adjust messaging configuration right from your Account Portal.

With every Messaging Service, you start by configuring the Inbound Request URL and Status Callback URL. For advanced configuration, Twilio Copilot Features are available to add intelligence to your application.

When sending messages, you must associate one or more phone numbers and/or short codes to your Messaging Service. One of the phone numbers in your Messaging Service will be chosen based on the enabled Copilot Features whenever you send an outbound message.

Alphanumeric Sender ID

Alphanumeric sender IDs are used for branded one-way messaging. Alphanumeric sender IDs may be used at no additional cost when sending an SMS to countries that are supported. Accepted characters include both upper- and lower-case ASCII letters, the digits 0 through 9, and space: [A-Za-z0-9 ]. When using an alphanumeric sender ID, at least 1 letter and no more than 11 alphanumeric characters may be used.

Alphanumeric sender IDs can be enabled in your SMS Settings.

Rate limiting

Your messages may be rate limited at different rates based on the destination you're sending messages to. For example, for US/CA destinations the limit is one message per second. Internationally, the upper limit is 10 MPS. For more information, check out this FAQ.

If you anticipate the need to send out a large number of messages quickly (a time-limited promotion, for example) or at a rate greater than one message per second, you can also purchase additional numbers, increasing your outbound capacity.

Short codes are not subject to the same rate limits as long-code numbers and may be a better option for you. Check out our short code FAQ to determine what is best for you.

Handling Message Replies

By specifying a Message URL for your messaging enabled Twilio phone number, Twilio will make a request to your application to notify you when someone replies to a message you send. Twilio's request and your corresponding response are covered in the Message portion of the TwiML documentation.

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
SDK Version:
  • 4.x
  • 5.x
Response Format:
  • json
  • xml
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.messages.create({
    body: "Jenny please?! I love you <3",
    to: "+15558675309",
    from: "+14158141829",
    mediaUrl: "http://www.example.com/hearts.png"
}, function(err, message) {
    process.stdout.write(message.sid);
});
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.messages.create({
  body: 'Jenny please?! I love you <3',
  to: '+15558675309',
  from: '+14158141829',
  mediaUrl: 'http://www.example.com/hearts.png',
})
.then((message) => process.stdout.write(message.sid));
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    
    var message = twilio.SendMessage("+14158141829", "+15558675309", "Jenny please?! I love you <3", new string[] {"http://www.example.com/hearts.png"});
    
    Console.WriteLine(message.Sid);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$client->account->messages->sendMessage("+14158141829", "+15558675309", "Jenny please?! I love you <3", "http://www.example.com/hearts.png");
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

message = @client.account.messages.create(
  :body => "Jenny please?! I love you <3",
  :to => "+15558675309",
  :from => "+14158141829",
  :media_url => "http://www.example.com/hearts.png")
puts message.to
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using System.Collections.Generic;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var mediaUrl = new List<Uri>() {
            new Uri("http://www.example.com/hearts.png")
        };
        var to = new PhoneNumber("+14158141829");
        var message = MessageResource.Create(to,
                                             from: new PhoneNumber("+15558675309"),
                                             body: "Jenny please?! I love you <3",
                                             mediaUrl: mediaUrl);

        Console.WriteLine(message.Sid);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$client->messages
    ->create(
        "+15558675309",
        array(
            "from" => "+14158141829",
            "body" => "Jenny please?! I love you <3",
            "mediaUrl" => "http://www.example.com/hearts.png"
        )
    );
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

message = client.messages.create(body="Jenny please?! I love you <3",
    to="+15558675309",
    from_="+14158141829",
    media_url="http://www.example.com/hearts.png")
print(message.sid)
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
require 'twilio-ruby'

# put your own credentials here
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new(account_sid, auth_token)

message = @client.account.messages.create(
  body: 'Jenny please?! I love you <3',
  to: '+15558675309',
  from: '+14158141829',
  media_url: 'http://www.example.com/hearts.png'
)

puts message.to
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.MessageFactory;
import com.twilio.sdk.resource.instance.Message;
import com.twilio.sdk.resource.list.MessageList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the MessageList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Body", "Jenny please?! I love you <3"));
    params.add(new BasicNameValuePair("To", "+15558675309"));
    params.add(new BasicNameValuePair("From", "+14158141829"));
    params.add(new BasicNameValuePair("MediaUrl", "http://www.example.com/hearts.png"));
    
    
    MessageFactory messageFactory = client.getAccount().getMessageFactory();
    Message message = messageFactory.create(params);
    System.out.println(message.getSid());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

message = client.messages.create(
        "+15558675309",
        body="Jenny please?! I love you <3",
        from_="+14158141829",
        media_url="http://www.example.com/hearts.png")

print(message.sid)
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

public class Example {
  /// Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Message message = Message
        .creator(new PhoneNumber("+15558675309"), new PhoneNumber("+14158141829"),
            "Jenny please?! I love you <3")
        .setMediaUrl("http://www.example.com/hearts.png")
        .create();

    System.out.println(message.getSid());
  }
}
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages \
    -d "Body=Jenny%20please%3F%21%20I%20love%20you%20<3" \
    -d "To=%2B15558675309" \
    -d "From=%2B14158141829" \
    -d "MediaUrl=http://www.example.com/hearts.png" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
    -d "Body=Jenny%20please%3F%21%20I%20love%20you%20<3" \
    -d "To=%2B15558675309" \
    -d "From=%2B14158141829" \
    -d "MediaUrl=http://www.example.com/hearts.png" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
   "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
   "api_version": "2010-04-01",
   "body": "Jenny please?! I love you <3",
   "num_segments": "1",
   "num_media": "1",
   "date_created": "Wed, 18 Aug 2010 20:01:40 +0000",
   "date_sent": null,
   "date_updated": "Wed, 18 Aug 2010 20:01:40 +0000",
   "direction": "outbound-api",
   "error_code": null,
   "error_message": null,
   "from": "+14158141829",
   "price": null,
   "sid": "MM90c6fc909d8504d45ecdb3a3d5b3556e",
   "status": "queued",
   "to": "+15558675309",
   "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MM90c6fc909d8504d45ecdb3a3d5b3556e.json"
}
<TwilioResponse>
	<Message>
		<Sid>MM90c6fc909d8504d45ecdb3a3d5b3556e</Sid>
		<DateCreated>Wed, 18 Aug 2010 20:01:40 +0000</DateCreated>
		<DateUpdated>Wed, 18 Aug 2010 20:01:40 +0000</DateUpdated>
		<DateSent/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<From>+14159352345</From>
		<To>+15558675309</To>
		<Body>Jenny please?! I love you &lt;3</Body>
        <NumSegments>1</NumSegments>
        <NumMedia>1</NumMedia>
		<Status>queued</Status>
		<Direction>outbound-api</Direction>
		<ApiVersion>2010-04-01</ApiVersion>
		<Price/>
		<PriceUnit>/>
		<ErrorCode/>
		<ErrorMessage/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MM90c6fc909d8504d45ecdb3a3d5b3556e</Uri>
	</Message>
</TwilioResponse>