Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

Send an MMS with Twilio using a media URL

See more Twilio Examples

Send an image and an optional caption from an MMS-capable Twilio number. Supply an MMS-supported destination in E.164 format and replace the example media URL with an HTTPS URL Twilio can fetch. The host must handle HEAD and GET and return the correct Content-Type for the file.

Live send. With live credentials and valid inputs, this request submits a billable message. Save the Message SID to check delivery later. Supported media types and size limits.

Twilio Messages API reference

Chilkat Rust Downloads

Rust
let mut success = false;

// Assumes Chilkat is unlocked. See Global Unlock Sample.
let http = chilkat::Http::new();
http.set_require_ssl_cert_verify(true);
http.set_basic_auth(true);
// Load the owning Account SID and an API key from application configuration.
let account_sid = "YOUR_ACCOUNT_SID".to_string();
http.set_login("YOUR_API_KEY_SID");
http.set_password("YOUR_API_KEY_SECRET");
let url = chilkat::StringBuilder::new();
let _ = url.append("https://api.twilio.com/2010-04-01/Accounts/");
let _ = url.append(&account_sid);
let _ = url.append("/Messages.json");

// Add raw field values. Chilkat form-encodes them, including the + in a phone number.
let req = chilkat::HttpRequest::new();
req.set_http_verb("POST");
req.set_content_type("application/x-www-form-urlencoded");
req.add_param("From", "YOUR_MMS_ENABLED_NUMBER");
req.add_param("To", "RECIPIENT_E164_NUMBER");
// Supply a URL for the file itself so Twilio can retrieve the media.
req.add_param("MediaUrl", "https://media.example.com/photo.jpg");
req.add_param("Body", "Photo attached.");

let resp = chilkat::HttpResponse::new();
let reply = chilkat::JsonObject::new();
success = http.http_req(&url.get_as_string().unwrap_or_default(), &req, &resp).is_ok();
if resp.status_code() == 0 {
    println!("{}", http.last_error_text());
    return;
}

let parsed = reply.load(&resp.body_str()).is_ok();
if (!success) || (resp.status_code() != 201) {
    println!("HTTP {}", resp.status_code());
    if (parsed) && (reply.has_member("code")) {
        println!("Twilio error {}: {}", reply.int_of("code"), reply.string_of("message").unwrap_or_default());
    }

    return;
}

if !parsed {
    println!("Expected a JSON response.");
    return;
}

if (reply.json_type_of("sid") != 1) || (reply.json_type_of("status") != 1) {
    println!("The create response is missing the message SID or status.");
    return;
}

println!("Message SID: {}", reply.string_of("sid").unwrap_or_default());
println!("Initial status: {}", reply.string_of("status").unwrap_or_default());