Sending Personalized SMS

Say you have a thousand SMS or more to send and you want to customize the message body to include their name. How would you do it? Sending each and every one manually by hand, typing on your phone would probably take a very long time.

You can actually do it programmatically with an Android phone and a PC/Mac. A continuation from my previous story of sending SMS with ADB, we now add on a script to read a list of recipients’ number and name, substitute the name onto the template and send.

First, we start with the list. Lets name it “list.txt” and it should look something like this

+6587654321|Kevin
+6598765432|Foo

Next, the ruby script to read “list.txt” and send SMS. Lets name it “send_sms.rb”.

def send(strPhoneNumber, strMessage)
`./adb shell service call isms 7 i32 0 s16 "null" s16 "#{strPhoneNumber}" s16 "null" s16 "'#{strMessage}'"`
end

template='Hello %s'
rows=(`cat list.txt`).split("\n")
for z in 0..rows.length-1
row=rows[z]
phone_number=row.split('|')[0]
name=row.split('|')[1]
message=template % [name]
send(phone_number,message)
puts 'sent to %s' % [name]
sleep(1)
end

To run the script above. Just type

ruby send_sms.rb

If you do not have ruby in your Mac, you can always install it with

brew install ruby

If you do not have Homebrew, you can install it simply by copy/pasting the command found at it’s official site.

Replace the template with your desired message. Change the sleep duration to a longer duration between send if your telco is strict.

< Back to all the stories I had written

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store