Welcome folks today in this tutorial we will be using fast2sms
api to send text sms messages to any mobile number in python 3. All the source code of the application will be shown below.
Get Started
In order to get started you need to be having python 3
installed on your computer and also just create a account on fast2sms here.
After that you need to get api key
for your account to send sms messages using fast2sms. To get the api key you need to go to dashboard and go to dev api
section as shown in the figure also.
And after that you will see the api key
inside the section as shown below. Just copy it and store it somewhere we will use it later.
After getting the api key
just create a app.py
file inside the root directory and copy paste the following code to it
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import requests import json # mention url url = "https://www.fast2sms.com/dev/bulk" # create a dictionary my_data = { # Your default Sender ID 'sender_id': 'FSTSMS', # Put your message here! 'message': 'This is a test message', 'language': 'english', 'route': 'p', # You can send sms to multiple numbers # separated by comma. 'numbers': '###yourmobilenumber####' } # create a dictionary headers = { 'authorization': '######YOURAPIKEY#######', 'Content-Type': "application/x-www-form-urlencoded", 'Cache-Control': "no-cache" } # make a post request response = requests.request("POST",url,data = my_data,headers = headers) returned_msg = json.loads(response.text) # print the send message print(returned_msg['message']) |
Here you just need to replace your own api key
and mobile number
where you need to send sms text message respectively.
After replacing the above things you can run the python script by executing the following command as follows
python app.py
After this you will receive a sms text message like this on your mobile number