PowerShell Requires Chilkat v11.0.0+
PowerShell
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.
Chilkat PowerShell Downloads
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"
$success = $false
# Assumes Chilkat is unlocked. See Global Unlock Sample.
$http = New-Object Chilkat.Http
$http.RequireSslCertVerify = $true
$http.BasicAuth = $true
# Load the owning Account SID and an API key from application configuration.
$accountSid = "YOUR_ACCOUNT_SID"
$http.Login = "YOUR_API_KEY_SID"
$http.Password = "YOUR_API_KEY_SECRET"
$url = New-Object Chilkat.StringBuilder
$url.Append("https://api.twilio.com/2010-04-01/Accounts/")
$url.Append($accountSid)
$url.Append("/Messages.json")
# Add raw field values. Chilkat form-encodes them, including the + in a phone number.
$req = New-Object Chilkat.HttpRequest
$req.HttpVerb = "POST"
$req.ContentType = "application/x-www-form-urlencoded"
$req.AddParam("From","YOUR_MMS_ENABLED_NUMBER")
$req.AddParam("To","RECIPIENT_E164_NUMBER")
# Supply a URL for the file itself so Twilio can retrieve the media.
$req.AddParam("MediaUrl","https://media.example.com/photo.jpg")
$req.AddParam("Body","Photo attached.")
$resp = New-Object Chilkat.HttpResponse
$reply = New-Object Chilkat.JsonObject
$success = $http.HttpReq($url.GetAsString(),$req,$resp)
if ($resp.StatusCode -eq 0) {
$($http.LastErrorText)
exit
}
$parsed = $reply.Load($resp.BodyStr)
if (($success -ne $true) -or ($resp.StatusCode -ne 201)) {
$("HTTP " + $resp.StatusCode)
if (($parsed -eq $true) -and ($reply.HasMember("code") -eq $true)) {
$("Twilio error " + $reply.IntOf("code") + ": " + $reply.StringOf("message"))
}
exit
}
if ($parsed -ne $true) {
$("Expected a JSON response.")
exit
}
if (($reply.JsonTypeOf("sid") -ne 1) -or ($reply.JsonTypeOf("status") -ne 1)) {
$("The create response is missing the message SID or status.")
exit
}
$("Message SID: " + $reply.StringOf("sid"))
$("Initial status: " + $reply.StringOf("status"))