A quick script to send an SMS message to a list of recipients using Termux-API and Python3 on an Android device.
-
Install the Termux app from the Google Play Store: https://play.google.com/store/apps/details?id=com.termux
-
Once installed, run Termux
-
Update Apt
apt-get update
- Install Termux-API
apt-get install termux-api
- Test the SMS send command in Termux and allow Android to access the SMS functions on the phone
termux-sms-send -n [replace with phone number] [SMS message]
- Install Python
apt-get install python
- Install Nano text editor
apt-get install nano
- Create the python Script
nano sendsms.py
- Write the script
import subprocess
# Add Entries to the address book dictionary. Key = Name, Value = Phone Number
addressbook = {"Name1" : "+15551234567"
"Name2" : "+15551234568"
}
# Loop through the addressbook dictionary and send each number the message
for (k,v) in addressbook.items():
# SMS Message Template (try to keep to within 150 characters)
smsmessage = str("Hi " + k + " your phone number is " + v)
# Use Subprocess Run Function to send SMS
subprocess.run(["termux-sms-send", "-n", phonenumber, smsmessage])
# Print confirmation of each send
print("Sent Message to " + k + " via " + v)
# Print end of process message
print("Message sending complete")
-
Save the python script and exit nano by pressing CTRL+X in Nano
-
Run the script in Termux
python sendsms.py
The termux terminal will display the following
Sent Message to Name1 via +15551234567
Sent Message to Name2 via +15551234568
Message sending complete