There are a number of methods really you should utilize Python to ship your new yr greetings by textual content messages.
Technique 1. A tweak of the e-mail sending choice.
As lots of you might remember, many cellphone carriers help you ship textual content messages utilizing e mail. Listed here are only a brief listing for main carriers within the United State.
- AT&T: [email protected]
- Dash: [email protected]
- T-Cellular: [email protected]
- Verizon: [email protected]
So as a substitute of utilizing the e-mail handle for the
email_receivers variable, you possibly can merely use [email protected] as one of many e mail recipients.
Nonetheless, there’s a catch as you could have to know the service related that quantity. For those who don’t comprehend it, you possibly can simply write some code to create all doable variations (e.g., [email protected], [email protected]) to cowl all prospects. I’ve additionally heard that there’s paid third-party service permitting you to search for a sure cellphone quantity’s service. However I suppose it’s an overkill for the target we’re making an attempt to perform.
Technique 2. Ship by way of AWS
You may also ship textual content messages utilizing AWS SNS. Apparently, you’ll want to join an AWS account, which is past the scope of the present tutorial. You may discuss with the official web site (https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
First, set up the AWS boto3 module.
Run the code (
pip set up boto3) in Terminal or a command line software. The boto3 library is a Python module developed for AWS-related administration.
Second, create an SNS consumer in Python.
The SNS is an AWS product that permits the builders to ship textual content messages and different communications (e.g., emails) to finish customers.
consumer = boto3.consumer(
aws_access_key_id="", # your aws entry key
aws_secret_access_key="", # your aws secrete entry key
Third, create a subject and add subscribers.
To ship your greeting to a number of cellphone numbers, you’ll want to create a subject, which lets you add subscribers to this subject. Every subscriber is specified by a cellphone quantity, which must also embrace the nation code (e.g., +1 for US) — the E.164 formatting. As a result of we’re sending messages (i.e., brief message service or sms), we specify the protocol to be
subject = consumer.create_topic(Identify="new_year") # create a subject
topic_arn = subject['TopicArn'] # get its Amazon Useful resource Identify# Add SMS Subscribers to this subject
phone_numbers = ["+1234567890"] for phone_number in phone_numbers:
Fourth, publish a message to the subject.
After getting added the subscribers to the subject, you’re able to publish a message to the subject. You simply want to offer the message and specify the subject on which you wish to publish this message. By doing that, all of the subscribers will obtain the textual content message.
consumer.publish(Message="Glad New Yr!", TopicArn=topic_arn)
Technique three. Ship by way of Twilio
You may also select to ship textual content messages utilizing the Twilio. Definitely, it requires a Twilio account, which is free to register, much like an AWS account. When you create a Twilio account, we’re able to play the sport!
First, set up the Twilio module.
Run the command
pip set up twilio to put in the Twilio module, which gives you entry to varied functionalities offered by Twilio. Textual content messaging is only one of them.
Second, create a Twilio consumer in Python
Cilent technique will probably be used to create a Twilio consumer by taking your Twilio account SID and AUTH Token, each of which will be discovered on the dashboard of your Twilio account.
from twilio.relaxation import Shopperconsumer = Shopper(
"", # your Twilio Account SID
"", # your Twilio AUTH token
Third, create and ship message.
You create an inventory of all of the cellphone numbers to which you’ll ship your new yr greetings. Once more, be famous that the cellphone quantity is utilizing the E.164 formatting much like the usage of AWS SNS.
One catch is that with free Twilio account, you possibly can solely ship textual content messages to you verified cellphone numbers, supplying you with much less flexibility in comparison with AWS SNS. Nonetheless, you possibly can improve your Twilio account, which gives you an choice of sending to a number of cellphone numbers of your alternative at very low price (lower than 1 cent per message).
phone_numbers = ["+1234567890", "+1234567891"] # the listing of cellphone numbers to obtain the messagesfor phone_number in phone_numbers:
from_="", # your Twilio cellphone quantity
physique="Glad New Yr!"