Send an SMS Text Message from the Command Line
When you think of sending out text messages you probably think of the iPhone or an Android, and the command line doesn’t cross your mind, but thanks to the ever-useful curl command, you can send out a SMS text message to any phone number right from the Terminal.
Yes, curl, the same command line tool for transferring data to and from URL’s, downloading files, getting HTTP header details, and so much more, can send text messages. This is done through a POST request sent to the TextBelt service, a free outgoing SMS API. Sure there are limits, but they’re fairly generous at 75 texts per day (per IP), and you can’t send a number more than 3 texts in three minutes to prevent abuse. Aside from that, keep in mind that you’ll be charged for incoming texts at the regular SMS / texting rate from your cell provider – this does not use the iMessage service – so don’t overuse this if you don’t have an unlimited traditional texting plan.
Sending a Text Message from the Command Line with curl
The basic syntax to use is as follows, be sure to replace the ########## with your own 10 digit phone number (10 digits = area code + phone number), and then replace the message= text with your own message to send:
curl http://textbelt.com/text -d number=########## -d "message=text goes here"
For example, to send a text saying “hello from OSXDaily.com” to the phone number 555-155-1555 (not a real number), you would use the following command string:
curl http://textbelt.com/text -d number=5551551555 -d "message=hello from OSXDaily.com"
Yes you could put another persons phone number in there too, but you probably should not do that without their permission.
If the text was successfully sent, the command line will return a message stating ‘{“success”:true}’, if it fails for whatever reason, it’ll look something like the following, which is usually indicative of an error in your command syntax: ‘{“success”:false,”message”: “Number and message parameters are required.”} curl: (6) Could not resolve host:’ Just review the command string and try again.
The text message should arrive to your iPhone or Android very quickly, though the expedience of the service likely depends on a queue and how much activity TextBelt is receiving from elsewhere. It’ll come through looking something like the following:
(If you’re wondering, responding to the texts goes nowhere and does nothing, it’s not a 2-way service)
This works to send texts from Mac OS X, Linux, and presumably whatever other OS or service has curl access. The recipient side should work with any mobile phone that accepts SMS, whether it’s an iPhone or an ancient brick Nokia.
Adding a Quick ‘Send Text’ Command to Bash
If you enjoy the convenience of sending yourself texts from the terminal and plan on using this often, you can create a simple bash script to shorten the command string by adding the following to your .bash_profile. Be sure to replace the number with your 10 digit phone number:
sendtext () { curl http://textbelt.com/text -d number=5551113333 -d "message=$1";echo message sent; }
With that in your bash_profile, you can simply type “sendtext your message goes here” to send out a text to yourself. This also allows for some fun and utility with double ampersands &&, like sending yourself SMS alerts when a software package has finished installing, or when a remote file is done downloading. Those with command line experience can probably think of a million and one other handy uses for this as well.
According to TextBelt, the service definitely works within the USA with the following cell networks: Alltel, Ameritech, AT&T Wireless, Boost, CellularOne, Cingular, Sprint PCS, Telus Mobility, T-Mobile, Metro PCS, Nextel, O2, Orange, Qwest, Rogers Wireless, US Cellular, Verizon, Virgin Mobile. This may be limited to the USA, but we’re unable to test networks outside of the region, let us know if you give it a try elsewhere.
Here is a very simple one line curl command to send sms text messages using textgun.io
“`
curl -i –user username:password -d “number=19179362841&message=hello world!” https://textgun.io/send-sms
“`
it worked perfectly for me, however, it is no longer free. They now require an authorization key and have a pricing structure:
$ curl http://textbelt.com/text -d number=########## -d “message=This is a test”
{“success”:false,”error”:”This Textbelt endpoint now requires a ‘key’ param. Please go to https://textbelt.com to sign up for an API key.”}
(phone number replaced with #’s for privacy)
Pricing tab on their website shows :
$3/20 texts
$5/100 texts
etc…
Its not working here in moon
Can confirm…
its not working for me i didnt get any message
To all people complaining about this not working in their country or no longer working … why not clone the project and set up a server in your own environment?
TextBelt has done a great job in clean development and documenting. This is easy enough to clone and customize to your own likings.
Or even better yet … update their code on github and see if they are willing to deploy your stuff in their production server.
In the end, if you want to run this yourself, all you need is an email client that is configured to connect to some mail server.
Phone providers tend to change their endpoints every now and then, breaking the TextBelt REST service. It’s easy enough to update the TextBelt configuration files to get it working again (unless of course if the phone provider decides to stop providing the email to SMS service, which has happened to me a couple times in the past).
Kind of interesting to delve through this TextBelt code and to learn how they get SMS messages sent out.
I’ve been struggling at my work to get automated monitoring SMS alerts sent out to on-call phones through our mailserver because of security constraints and have been looking for workarounds. I thought to have found the solution here through curl but turns out this TextBelt REST service is using the Mutt email client in its belly to do the heavy lifting. So it would still come down to having to go through our mail server and thus hitting that same security restriction.
Too bad. It looks like a great service and nicely coded! Congrats to TextBelt!
Its not working in India either.
yes!! It is not working in India
why donāt you try following
curl -X POST http://textbelt.com/intl -d number=0119779803744057 -d āmessage=testingā
Is this still working?
It doesnt seem to send text messages when I tried to US #’s.
i have not received any of my 100 text sent to my gv or my tmobile account.. is this still working
Aside from sending SMS from the command line, or the SendSMS Mac app (previously mentioned in one of the comments), you can also find some other Mac options now:
* Safari browser extension
* Mac OS X desktop widget
* other browser extensions (Chrome, Opera, Firefox)
find them here:
https://github.com/daluu/textbelt-clients/wiki/Textbelt-clients%2C-installation-and-download
And if this textbelt.com service not working so well for you and you can deal with CAPTCHA, then try this alternative option (no command line access due to CAPTCHA):
https://github.com/daluu/autosmsclients/wiki/AutoSMS-clients%2C-installation-and-download
Exactly what I was looking for. Unfortunately it doesn’t seem to work in France :/
Dial code for France is +33, 6 (or 7) indicates a cellphone, so I wrote:
curl http://textbelt.com/text -d number=+336xxxxxxxx -d “message=Is this really working?”
Am I missing something or it’s purposely not working for other countries.
How does it know which service to pick for a particular U.S. phone number? For e.g., my number has been ported all the way from At&T to T-Mobile to MetroPCS.
I did not receive the message when I tried this service, though I see {
“success”: true
}
But I was able to receive the message when I directly emailed XXXXXXXXXX@mymetropcs.com
File a bug on Github, if there isn’t one already regarding MetroPCS.
Thanks, FYI this does not work with phone numbers from Uruguay like :
01159899085323 where :
011 means :outside north america
598 means : uruguay
99 : means “antel” cell network
the rest is the phone number.
If anyone finds a way to send a text to that number, let me know please. I’d also like to find a way to reply with a code so that I can use it for remote monitoring and control.
Thanks, FYI this does not work with phone numbers from Uruguay.
Use the Uruguayan country code it will work like the magic that it is, command line text messaging
Too bad this unnecessarily requires a third party service –
How can I get the curl program? How much?
Open the Terminal and type ‘curl’, not much
Not working on Skype US numbers….
Doesn’t work on Mars either :-(
Does not work with Australian numbers.
If you want this to be even cooler, put this in your bash_profile:
sendtext () {
var=$*
var=${var#*$1}
curl http://textbelt.com/text -d number=$1 -d “message=$var”;
echo message sent;
}
This allows you to type “sendtext typephonenumberhere write your message here”. This way you can send custom messages to custom numbers without having to change your bash_profile every time!
I like this idea and so I am using it with vim but now I am stuck and can’t quit out of vim. Ended up using kill -9 LOL!!
Why is vim the hardest thing ever? I guess I’ll use something else…
We see this question a lot, the easiest way to quit out of vim is: Escape, SHIFT ZZ
Write-up coming up, I think it will help many. Generally most users are better off using nano or, depending on what they’re editing, even TextWrangler in the GUI.
The source code on GitHub suggests you can also do this yourself without having to go through TextBelt
where %s = your phone number
list: [
‘%s@message.alltel.com’,
‘%s@paging.acswireless.com’,
‘%s@txt.att.net’,
‘%s@myboostmobile.com’,
//’%s@sms.edgewireless.com’, // slow
‘%s@messaging.sprintpcs.com’,
‘%s@tmomail.net’,
‘%s@mymetropcs.com’,
‘%s@messaging.nextel.com’,
‘%s@mobile.celloneusa.com’,
‘%s@qwestmp.com’,
‘%s@pcs.rogers.com’,
‘%s@msg.telus.com’,
‘%s@email.uscc.net’,
‘%s@vtext.com’,
‘%s@vmobl.com’,
‘%s@txt.windmobile.ca’,
https://github.com/typpo/textbelt/blob/master/providers.js
The github link has changed:
https://github.com/typpo/textbelt/blob/master/lib/providers.js
It has a total of 140 URLs categorized in a dict (hash table) with keys ‘us’, ‘canada’ and ‘intl’.
would you mind if I post this on twitter?
Please do! We always appreciate when people share our stuff.
Doesn’t work in Luxembourg – but anyway: the “regular” approach is so much simpler to me :-) !
The title “Send an SMS Text Message from the Command Line” is misleading. It should read “Using a web service from command line”. The command line does not send a text in this case.
doesn’t seem to be working here in Toronto.
Some carriers (like Verizon) allow blocking of texts from the web and email. If you have that turned off, you won’t get these.
Is there a way too to send a fax with Curl?
Would be cool!
Is possible, but you’ll have to find a service provider that offers fax over HTTP/web. Then you just use curl to make the HTTP request sending over the fax “text” or if more complex, upload the fax document (Word, RTF, image, PDF) as part of the HTTP request.
Here’s some to give you an idea. But you’ll have figure out the parameters to fax. Bear in mind these are sites that offer a freebie and paid options. They don’t explicitly offer an API service, you’re kind of hacking (web scraping) an interface to them.
http://faxzero.com
http://www.gotfreefax.com
https://www.faxitnice.com/faxitnice/app/template/Index.vm
Ukraine, doesn’t work :(
Who are the people behind textbelt.com? why should we trust them?
Exactly what do you need to trust them with? The destination phone number? The message? I simply wouldn’t text anything this way that I wasn’t prepared to be seen by at least some people, if not the world. But that’s largely my attitude about any text.
This is same gateway that we use for SendSMS app http://www.mobiliodevelopment.com/sendsms-osx/
But you’re correct – works only on few US and Canada operators.
Doesn’t work in Spain either : /
Apparently it doesn’t work for Indonesian number with 62 prefix
{“success”:false,”message”:”Invalid phone number.”}
Does not work in Germany:
{“success”:false,”message”:”Invalid phone number.”}
The textbelt website confirms that they only support some US carriers (network operators).
Doesn’t work in the UK either
Worked for AT&T of course, but did not work for my Google Voice number. :(
now could a spammer use this? send out hundreds of these things. no trace back only the poor site that just get bombarded by text messages…
i could see it now
FRM:txt@textbelt.com
MSG:Sign up for Russian brides at http://www.fakewebsite.scammer
Probably not with “75 texts per day (per IP)”
If you’re a bulk SMS sender, there are services which offer many thousands a day. Or you can just use AIM (yes, AOL Instant Messenger! LOL!!!), because you can send endless texts through the AIM service by prefixing a message with +1
Maybe only in the US.I tried to send to a swedish mobile but I got “Invalid phone number”
Doesn’t work on Polish numbers (here we have 9 digits number and 2-3 for country code). So it returns {“success”:false,”message”:”Invalid phone number.”}.
It works in USA and Canada only, apparently. Maybe Mexico too if you can stay on a US cell tower, heh.
Anyway, this is cool, I will use it for notifications!
in canada,
PC mobility (president’s choice)
not working… will wait
bye
Wow this is cool, great trick!