|
| 1 | +<template> |
| 2 | + <v-container class="pt-8"> |
| 3 | + <v-row class="mt-16"> |
| 4 | + <v-col cols="12" md="9"> |
| 5 | + <v-img |
| 6 | + style="border-radius: 4px" |
| 7 | + alt="blog post header image" |
| 8 | + :src=" |
| 9 | + require('@/static/img/blog/send-sms-from-android-phone-with-python/header.png') |
| 10 | + " |
| 11 | + ></v-img> |
| 12 | + <h1 |
| 13 | + class="mt-1" |
| 14 | + :class="{ |
| 15 | + 'text-h2': $vuetify.breakpoint.mdAndUp, |
| 16 | + 'text-h3': !$vuetify.breakpoint.mdAndUp, |
| 17 | + }" |
| 18 | + > |
| 19 | + Send an SMS from your Android phone with Python |
| 20 | + </h1> |
| 21 | + <p class="subtitle-2 mt-2"> |
| 22 | + <span class="text-uppercase blue--text">{{ postDate }}</span> |
| 23 | + • <span class="text-uppercase">{{ readTime }}</span> |
| 24 | + </p> |
| 25 | + <p class="text--secondary subtitle-1 mt-2"> |
| 26 | + In an era dominated by social media, instant messaging apps, and |
| 27 | + ever-evolving communication technologies, it's easy to overlook the |
| 28 | + humble yet remarkably resilient Short Message Service (SMS). Since its |
| 29 | + inception in the 1990s, SMS has stood the test of time, remaining one |
| 30 | + of the most widely used and reliable means of mobile communication. |
| 31 | + </p> |
| 32 | + <p> |
| 33 | + Whether you're a business owner looking to optimize your communication |
| 34 | + strategy, a developer seeking to integrate SMS functionality into your |
| 35 | + applications, or simply intrigued by the enduring charm of SMS, this |
| 36 | + article will explain how to setup your Android phone to send SMS |
| 37 | + messages. |
| 38 | + </p> |
| 39 | + <h3 class="text-h4 mt-8 mb-2">Prerequisites</h3> |
| 40 | + <ul> |
| 41 | + <li>Basic understanding of Python.</li> |
| 42 | + <li>An Android phone.</li> |
| 43 | + <li> |
| 44 | + <a href="https://www.python.org/" class="text-decoration-none" |
| 45 | + >Python</a |
| 46 | + > |
| 47 | + installed on your computer. |
| 48 | + </li> |
| 49 | + </ul> |
| 50 | + <h3 class="text-h4 mt-8 mb-2">Step 1: Get your API Key</h3> |
| 51 | + <p> |
| 52 | + Create an account on |
| 53 | + <nuxt-link class="text-decoration-none" to="/">httpsms.com</nuxt-link> |
| 54 | + and copy your API key from the settings page |
| 55 | + <nuxt-link class="text-decoration-none" to="/settings" |
| 56 | + >https://httpsms.com/settings</nuxt-link |
| 57 | + > |
| 58 | + </p> |
| 59 | + <vue-glow |
| 60 | + color="#329ef4" |
| 61 | + mode="hex" |
| 62 | + elevation="14" |
| 63 | + :intensity="1.07" |
| 64 | + intense |
| 65 | + > |
| 66 | + <v-img |
| 67 | + style="border-radius: 4px" |
| 68 | + alt="httpsms.com settings page" |
| 69 | + :src=" |
| 70 | + require('@/static/img/blog/forward-incoming-sms-from-phone-to-webhook/settings.png') |
| 71 | + " |
| 72 | + ></v-img> |
| 73 | + </vue-glow> |
| 74 | + <h3 class="text-h4 mb-4 mt-16"> |
| 75 | + Step 2: Install the httpSMS android app |
| 76 | + </h3> |
| 77 | + <p> |
| 78 | + <a |
| 79 | + target="_blank" |
| 80 | + class="text-decoration-none" |
| 81 | + href="https://github.com/NdoleStudio/httpsms/releases/latest/download/HttpSms.apk" |
| 82 | + >⬇️ Download and install</a |
| 83 | + > |
| 84 | + the httpSMS android app on your phone and sign in using your API KEY |
| 85 | + which you copied above. This app listens for SMS messages received on |
| 86 | + your android phone. |
| 87 | + </p> |
| 88 | + <v-alert type="info" outlined> |
| 89 | + Make sure to enter your phone number in the international format e.g |
| 90 | + +18005550199 when authenticating with the httpSMS Android app. |
| 91 | + </v-alert> |
| 92 | + <v-img |
| 93 | + style="border-radius: 4px" |
| 94 | + alt="httpsms android app" |
| 95 | + height="800" |
| 96 | + contain |
| 97 | + :src=" |
| 98 | + require('@/static/img/blog/forward-incoming-sms-from-phone-to-webhook/android-app.png') |
| 99 | + " |
| 100 | + ></v-img> |
| 101 | + <h3 class="text-h4 mt-12">Step 3: Writing the code</h3> |
| 102 | + <p> |
| 103 | + Now that you have setup your android phone correctly on httpSMS, you |
| 104 | + can write the python code below in a new file named |
| 105 | + <code>send_sms.py</code>. This code will send and SMS and after |
| 106 | + running the script via your Android phone to the recipient phone |
| 107 | + number specified in the <code>payload</code>. |
| 108 | + </p> |
| 109 | + <v-alert type="info" outlined class="mt-2 mb-4"> |
| 110 | + Make sure to use the correct <code>api_key</code> from step 1 and also |
| 111 | + use the correct <code>to</code> and <code>from</code> phone numbers in |
| 112 | + the <code>payload</code> variable. |
| 113 | + </v-alert> |
| 114 | + <pre v-highlight class="python w-full mb-n9"> |
| 115 | +<code>import requests |
| 116 | +import json |
| 117 | + |
| 118 | +api_key = "" # Get API Key from https://httpsms.com/settings |
| 119 | + |
| 120 | +url = 'https://api.httpsms.com/v1/messages/send' |
| 121 | + |
| 122 | +headers = { |
| 123 | + 'x-api-key': api_key, |
| 124 | + 'Accept': 'application/json', |
| 125 | + 'Content-Type': 'application/json' |
| 126 | +} |
| 127 | + |
| 128 | +payload = { |
| 129 | + "content": "This is a sample text message sent via python", |
| 130 | + "from": "+18005550199", # This is the phone number of your android phone */ |
| 131 | + "to": "+18005550100" # This is the recipient phone number */ |
| 132 | +} |
| 133 | + |
| 134 | +response = requests.post(url, headers=headers, data=json.dumps(payload)) |
| 135 | + |
| 136 | +print(json.dumps(response.json(), indent=4)) |
| 137 | +</code> |
| 138 | + </pre> |
| 139 | + <p> |
| 140 | + Run the code above with the command |
| 141 | + <code>python send_sms.py</code> and check the phone specified in the |
| 142 | + <code>to</code> field of the <code>payload</code> to verify that the |
| 143 | + message has been received successfully. |
| 144 | + </p> |
| 145 | + <v-img |
| 146 | + style="border-radius: 4px" |
| 147 | + alt="httpsms android app" |
| 148 | + height="800" |
| 149 | + contain |
| 150 | + :src=" |
| 151 | + require('@/static/img/blog/send-sms-from-android-phone-with-python/sms-sent.png') |
| 152 | + " |
| 153 | + ></v-img> |
| 154 | + <h3 class="text-h4 mt-12">Conclusion</h3> |
| 155 | + <p> |
| 156 | + Congratulations, you have successfully configured your android phone |
| 157 | + to send SMS messages via python. You can now reuse this code to send |
| 158 | + SMS messages from your python applications. |
| 159 | + </p> |
| 160 | + <p> |
| 161 | + If you are also interested in forwarding incoming SMS from your |
| 162 | + android phone to your server, checkout our |
| 163 | + <nuxt-link |
| 164 | + to="/blog/forward-incoming-sms-from-phone-to-webhook" |
| 165 | + class="text-decoration-none" |
| 166 | + >SMS forwarding guide.</nuxt-link |
| 167 | + > |
| 168 | + </p> |
| 169 | + <p>Until the next time✌️</p> |
| 170 | + <div class="d-flex mb-6 mt-8"> |
| 171 | + <v-avatar class="mb-n2"> |
| 172 | + <v-img :src="authorImage"></v-img> |
| 173 | + </v-avatar> |
| 174 | + <div class="ml-2"> |
| 175 | + <p class="subtitle-1 mb-n1">{{ authorName }}</p> |
| 176 | + <a |
| 177 | + class="mb-n4 text-decoration-none text--primary" |
| 178 | + href="https://twitter.com/acho_arnold" |
| 179 | + > |
| 180 | + {{ authorTwitter }} |
| 181 | + <v-icon color="#1DA1F2" small>{{ mdiTwitter }}</v-icon> |
| 182 | + </a> |
| 183 | + </div> |
| 184 | + </div> |
| 185 | + <v-divider class="mx-16"></v-divider> |
| 186 | + <div class="text-center mt-8 mb-4"> |
| 187 | + <back-button></back-button> |
| 188 | + </div> |
| 189 | + </v-col> |
| 190 | + <v-col v-if="$vuetify.breakpoint.mdAndUp" md="3"> |
| 191 | + <blog-info></blog-info> |
| 192 | + </v-col> |
| 193 | + </v-row> |
| 194 | + </v-container> |
| 195 | +</template> |
| 196 | + |
| 197 | +<script lang="ts"> |
| 198 | +import { mdiTwitter } from '@mdi/js' |
| 199 | +export default { |
| 200 | + name: 'SendSmsFromAndroidPhoneWithPython', |
| 201 | + layout: 'website', |
| 202 | + data() { |
| 203 | + return { |
| 204 | + mdiTwitter, |
| 205 | + authorImage: require('@/assets/img/arnold.png'), |
| 206 | + authorName: 'Acho Arnold', |
| 207 | + postDate: 'June 03, 2023', |
| 208 | + readTime: '6 min read', |
| 209 | + authorTwitter: 'acho_arnold', |
| 210 | + } |
| 211 | + }, |
| 212 | + head() { |
| 213 | + return { |
| 214 | + title: 'Send an SMS from your Android phone with Python - httpSMS', |
| 215 | + meta: [ |
| 216 | + { |
| 217 | + hid: 'og:title', |
| 218 | + property: 'og:title', |
| 219 | + content: 'Send an SMS from your Android phone with Python', |
| 220 | + }, |
| 221 | + { |
| 222 | + hid: 'og:description', |
| 223 | + property: 'og:description', |
| 224 | + content: |
| 225 | + 'Configure your Android phone as an SMS gateway to automate sending text messages with the Python programing language.', |
| 226 | + }, |
| 227 | + { |
| 228 | + hid: 'og:image', |
| 229 | + property: 'og:image', |
| 230 | + content: |
| 231 | + 'https://httpsms.com/img/blog/send-sms-from-android-phone-with-python/header.png', |
| 232 | + }, |
| 233 | + { |
| 234 | + hid: 'twitter:card', |
| 235 | + name: 'twitter:card', |
| 236 | + content: 'summary_large_image', |
| 237 | + }, |
| 238 | + { |
| 239 | + hid: 'og:url', |
| 240 | + property: 'og:url', |
| 241 | + content: |
| 242 | + 'https://httpsms.com/blog/send-sms-from-android-phone-with-python', |
| 243 | + }, |
| 244 | + ], |
| 245 | + } |
| 246 | + }, |
| 247 | +} |
| 248 | +</script> |
0 commit comments