In many companies using IP-telephony and using GSM-gateways for corporate communications, the question often arises of receiving and sending SMS from their numbers.
For Chinese GOIP models, there is a good GOIP-SMS Server solution, which has been repeatedly mentioned on the Internet and in our Habr community as well. This is a simple, free and convenient product, but SMS via WEB, especially from mobile is not very convenient.
There was an idea of receiving and sending SMS using a messenger - and was implemented in an hour using a simple Python3.6 script and Telegram bot (and 2 months later it was transferred to Viber). I ask under the cat:
The logic is as follows: We process and parse the request, retrieve the body of SMS, send it to bots and send it to personal chats - we get SMS, the topic is especially interesting for iPhone owners with 1 sim, when you quickly need to receive messages on a business trip or vacation, from banks or registration services or find out about operator replenishment:
So, we will consider the first part, namely, how to receive full-fledged SMS from a GSM network directly in Telegram, we need:
- GoIP SMS Server
- Register the bot (get your TOKEN from the dad of all bots @BotFather)
- Register a new mailbox on Gmail and enable IMAP reception
We’ll analyze an example script, but first add the recipient’s email address to the SMS server (several email addresses can be separated by commas:
Consider the script:
import imaplib import email import telebot
Now we run the script, send SMS to our Sim and wait for processing - about 3 seconds it takes to transfer SMS to the messenger, if everything is correct, then we see our messages in our TelegramBot
(real numbers erased in order to avoid "Spring" conflicts):
You can wrap the script in a “def function” and call it every 3 or 20, or for how many seconds you need! Depends on the frequency of receiving SMS ok!
If someone doesn’t manage to repeat, write - we will analyze each case ...
See you in the next article!
73!
PS: the article lasted for about a year in the sandbox (approved by UFO on 08/20/2018) has undergone several changes, apparently the old articles do not automatically come, even if the new article allowed to become a full member. I publish the original original.
Now it can be discussed.