Today’s topic is using the Python library Twilio to send free text messages.

Let’s start with a finished product:

The code is in the address at the end of this article, please feel free to help yourself, if you have any, you can talk to me directly in the comments or background.

Private Reply [PDF] A set of Python e-books is available

The body of the

Sharp-eyed friends have noticed that the prefix of the message above shows that this message is from a free account called Twilio. The library we use today is Twilio. Since it is a free account, there must be some restrictions, which will be mentioned later.

In addition, we should pay attention to the fact that when this website is visited from home, it may be impossible to visit because of some reasons you know, so we have to learn how to surf the Internet scientifically.

1.Twilio

Twilio is a call-tracking service made as an open plug-in. Twilio, a cloud communications company, went public on the New York Stock Exchange on June 23, 2016 local time.

2. Install

The official documentation address: https://www.twilio.com/docs/libraries/python

Support for the following languages is also available

As you can see, it’s still very rich.

The simplest way to do this is through PIP, with the following command:

pip install twilio
Copy the code

3. Set up an account

After installing the library, you need to register on the official web page.

Visit the official website: https://www.twilio.com

Then go to the registration page

Then through the man-machine authentication, will be authenticated to your mobile phone number, this will not send pictures.

4. Enter the console

Once registered, we can access our own panel

The arrows in the figure point to two parameters that we need in our code, so we can copy both;

Since be texting, then must be have a receiver and a sender, the sender’s number is not just fill in the number of our own, and twilio assign a number to us, because I also do a good job in a long time, so don’t remember this number is the beginning in some, if not, So click Get stupid.

Now let’s hit Manage Numbers

That’s when you’ll see our numbers. That’s the point. Write it down

5. Write the code

Based on the contents of the document, we wrote the following code:

Then execute the program and you should encounter the following error

Can be seen from the error message obviously, prompting us to say that this number is not verified, we can verify to the verified website, can also buy a high-level account to send information to the number not verified.

And this is the limitation of the free account THAT I mentioned at the beginning, where if you want to send a message to a recipient, the recipient’s number must be authenticated, either by voice authentication or SMS authentication. If you want to send that kind of spam in bulk, then you need look no further. Now let’s verify the number.

6. Verify the number

Verify the url: https://www.twilio.com/console/phone-numbers/verified

7. Re-execute the code

Re-execute our code at this point, and if there are no errors, the recipient should receive your message, just like the finished image I showed you at the beginning.

However, in front of the message we sent, there was a prefix, I checked the official documentation, it said that this free account, this prefix can not be removed…

8. Check your dosage

In the panel, click Usage to see our Usage, as shown in the picture below

We can see our usage and expenses, which do not need to be paid by us. The official explanation is:

9. Make a phone call

The code for making a phone call is also simple

After executing the program, the phone will be connected, but the person inside will prompt you to upgrade your account…

conclusion

Well, here we can send text messages for free.

With this library, we can:

(1) Monitor online or offline background running programs, and send SMS alarm in time

(2) Playing with raspberry PI can realize monitoring of many scenes

The code is in here: https://github.com/xiaosimao/wx_code/tree/master/send_sms

Have you learned? Get a move on!