How to send SMS using Python
In this article, we will learn to send SMS using Python with the help of Fast2SMS Service. There are many online services which provide API for the sending free SMS like Twilio ,way2sms , Fast2sms etc.
Twilio is the most popular among them, but Twilio has a lot of restrictions in India. We are using Fast2SMS service here.
First sign up to Fast2SMS using this. Then you will be assigned with an API authorisation key, which is needed to be included in the Python code.
You can send 20 free SMS daily. The message is sent with your mobile number as initials.
Th below given code will provide an idea how this works. Include your API auth key, message to be sent and also include the mobile number of the recipients.
import requests url = "https://www.fast2sms.com/dev/bulk" payload = "sender_id=FSTSMS&message=test&language=english&route=p&numbers=9999999999,888888888" headers = { 'authorization': "YOUR_AUTH_KEY", 'Content-Type': "application/x-www-form-urlencoded", 'Cache-Control': "no-cache", } response = requests.request("POST", url, data=payload, headers=headers) print(response.text)
For example If you want to send an “Good Morning” message to a recipients with mobile number 985411279 and 854112799 , then payload in the code changes to
payload = "sender_id=FSTSMS&message=GoodMorning&language=english&route=p&numbers=985411279,854112799"
For more info : docs.fast2sms.com