This is the 11th day of my participation in the August More text Challenge. For details, see: August More Text Challenge

In the last article, we explained in detail how to purchase SMS service from SMS service provider, and made a small service of SMS notification of weather forecast. However, there is a charge for using the SMS interface provided by the domestic SMS service provider. So what about that “pie in the sky” — free TEXTING access? The answer, of course, is YES! Today we’re going to learn about two free ways to send text messages. Attention! Both of the two free SMS interfaces covered in this article have some limitations, which I will explain in the article and in the summary of this article. Before reading this article, you can go to the summary to see the limitations of the interface.

Twilio – API site for developers

Twilio is a foreign cloud communication platform, which is listed on nasdaq. It allows software developers to make and receive phone calls programmatically. Twilio provides us with a free but partially limited interface. This article starts with Twilio’s free interface.

Register and verify information

To ensure smooth registration, you may need scientific access to the Internet.

First, let’s go to the home page of Twilio and click Get a free API key to enter the registration interface.

On the registration page, you can follow the tips below to register.

After clicking submit, the system will send a verification message to your mobile phone, you can directly enter the verification code.

Configure the background

As shown in the figure below, after creating the application, we enter the background of the CONSOLE, where Twilio assigns us a mobile phone number for sending SMS messages.

We clickGet a numberThen the system randomly assigns us a number to send a message to:

After confirming the mobile phone number of the system, the system will jump to a web test page. Here we can directly input some brief information to test whether the phone can send successfully. At the same time, the right side also provides the corresponding code, convenient for us to browse.

We clickmake requests, the system will help us to send a test text message to our mobile phones. If you receive the corresponding SMS message, the configuration is successful. Next we begin the formal development work!

The development of the configuration
  1. The repository

First we need to install the Python library Twilio:

pip install twilio

  1. Browse development documents

The Twilio website provides a wealth of interface documentation. Let’s take a look at the Python interface instance documentation. It provides a short message DEMO, and uses Python version 3.x, so we do not need to consider Python 2.x conversion for this development.

Attention! Make sure your phone number has been verified in Twilio before using the interface, otherwise it will fail to be sent! You can check whether your phone has been added to Twilio by checking your phone number!

  1. Configuring User Information

We noticed that in the development document, we were required to provide the corresponding ACCOUNT SID and AUTH TOKEN. We went to the CONSOLE page and noticed that the corresponding field information we needed was in the upper right corner:

4. Development test let’s modify the code and try to use the free interface to send SMS to our mobile phone number:

from twilio.rest import Client
# Your Account SID from twilio.com/console
account_sid = "AC141778d2eed2ba022112c91157426103"
# Your Auth Token from twilio.com/console
auth_token  = "your_auth_token"
client = Client(account_sid, auth_token)
message = client.messages.create(
    to="+ 15558675309", 
    from_="+ 15017250604",
    body="Hello, world!)
print(message.sid)
Copy the code

Let’s wait for….. Did you find that you haven’t received the text message on your phone? Yes! Twilio provides free interface, temporarily does not support Chinese SMS! So let’s change the text in the body to English and try again:

It’s normal next time! The phone soon received a corresponding text message.

Email – It’s not just email

Email 139 is an email service provided by China Mobile for China Mobile users, but currently anyone can apply for it for free (mobile users open it by default). We can use its email notification service: send emails to our mailbox 139, and then send them to our mobile phones through text messages, to achieve the effect of free text messages.

In order to use the email notification service, you must bind the corresponding mobile phone number when applying for email 139

After registering email 139, we first log on to the email home page and click one by oneSet up the->Email filtering and reminders, the reminder configuration page is displayed.Short message displaychooseShown separately, and save the configuration:

Modify the weather forecast code

  1. Twilio sends text messages

To match Twilio’s SDK, we need to rewrite the code for sending SMS:

from twilio.rest import Client
account_sid = ""
auth_token  = ""
client = Client(account_sid, auth_token)
def send_sms(to_number,from_number,sms_text) :
    message = client.messages.create(
        to=to_number,
        from_=from_number,
        body=sms_text)
    print(message.sid)
Copy the code
  1. 139 Sending SMS messages through email

Did you forget the code we used to send emails? That’s right! Directly use the previous code can be!

conclusion

  1. This article introduces two kinds of free SMS interface, which is convenient for the students who have some tight money to enjoy the SMS reminder service. What we’re going to end up doing, after all, is a messaging service;
  2. Twilio does not support Chinese text messages, and you must verify your phone number before sending them. The mailbox must be registered and configured with the email notification function to receive the corresponding SMS messages.
  3. The text doesn’t go into detail about sending text messages via 139 mail, because the course was written with the extensibility of the program in mind, encapsulating every function. After learning, I hope you can take out the email sending code that you wrote before and try to send a text message to your phone using 139.