Send an SMS from your Android phone with Python
June 03, 2023 • 6 min read
In an era dominated by social media, instant messaging apps, and ever-evolving communication technologies, it's easy to overlook the humble yet remarkably resilient Short Message Service (SMS). Since its inception in the 1990s, SMS has stood the test of time, remaining one of the most widely used and reliable means of mobile communication.
Whether you're a business owner looking to optimize your communication strategy, a developer seeking to integrate SMS functionality into your applications, or simply intrigued by the enduring charm of SMS, this article will explain how to setup your Android phone to send SMS messages.
Prerequisites
- Basic understanding of Python.
- An Android phone.
- Python installed on your computer.
Step 1: Get your API Key
Create an account on httpsms.com and copy your API key from the settings page https://httpsms.com/settings
Step 2: Install the httpSMS android app
⬇️ Download and install the httpSMS android app on your phone and sign in using your API KEY which you copied above. This app listens for SMS messages received on your android phone.
Step 3: Writing the code
Now that you have setup your android phone correctly on httpSMS, you
can write the python code below in a new file named
send_sms.py
. This code will send and SMS and after
running the script via your Android phone to the recipient phone
number specified in the payload
.
api_key
from step 1 and also
use the correct to
and from
phone numbers in
the payload
variable.
import requests
import json
api_key = "" # Get API Key from https://httpsms.com/settings
url = 'https://api.httpsms.com/v1/messages/send'
headers = {
'x-api-key': api_key,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
payload = {
"content": "This is a sample text message sent via python",
"from": "+18005550199", # This is the phone number of your android phone */
"to": "+18005550100" # This is the recipient phone number */
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
print(json.dumps(response.json(), indent=4))
Run the code above with the command
python send_sms.py
and check the phone specified in the
to
field of the payload
to verify that the
message has been received successfully.
Conclusion
Congratulations, you have successfully configured your android phone to send SMS messages via python. You can now reuse this code to send SMS messages from your python applications.
If you are also interested in forwarding incoming SMS from your android phone to your server, checkout our SMS forwarding guide.
Until the next time✌️