Send SMS Using Python
In this post, we will see how to send an SMS using Python.
Python is a popular programming language among developers, so many packages can do most of the complex tasks for us.
To send an SMS, we are going to use the Twilio
Prerequisites
- First visit the Twilio website and create an account
- Next copy your account sid and token
Installation
Run the below command to install Twilio.
pip install twilio
Now the below code is the main logic that we are going to use.
# importing twilio
from twilio.rest import Client
# Replace the credentials with your details
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
# Change the from and to numbers to whatever you want
message = client.messages.create(
from_='+000000000',
body ='body of the message',
to ='+0000000000'
)
print(message.sid)
Now run this program with the below command,
python filename.py
That's it, the message will be sent successfully.