How to send text messages with Python for Free

This week, I am going to be showing you how to send text messages with Python for free. It’s actually surprisingly easy to do and I thought it could be useful to share this with all of you!


What you’ll need

For this post, I’ll be using the following:

It should be noted that if you’re using gmail, like me, you’ll need to setup and use an application password with your account. You can read more information and security warnings on that here:



import smtplib
import sys
"att": "",
"tmobile": "",
"verizon": "",
"sprint": ""
def send_message(phone_number, carrier, message):
recipient = phone_number + CARRIERS[carrier]
server = smtplib.SMTP("", 587)
server.login(auth[0], auth[1])
server.sendmail(auth[0], recipient, message)
if __name__ == "__main__":
if len(sys.argv) < 4:
print(f"Usage: python3 {sys.argv[0]} <PHONE_NUMBER> <CARRIER> <MESSAGE>")
phone_number = sys.argv[1]
carrier = sys.argv[2]
message = sys.argv[3]
send_message(phone_number, carrier, message)

Running Code

If you copied my code sample above, you can run this script from any terminal within the same directory as this file with:

python3 1234567891 att "This is a sample text message"

Of course you’ll want to specify the carrier that you actually use in order for this to work.



This week’s blog post was short and sweet, but it’s something that I use pretty often. Sometimes I use this method to send me text messages whenever I need a project to notify me of anything. Whenever I do this, I typically use a throwaway email because I don’t want to open application passwords on any account I might consider to be important.

Hopefully this neat trick is as useful for you as it is for me!

As always, if you liked what you read and you’d like to support me, please consider buying me some coffee! Every cup of coffee sent my way helps me stay awake after my full-time job so that I can produce more high quality blog posts! Any and all support would be greatly appreciated!

Ballad Serial — Trans Arsonist Art Network

3 thoughts on “How to send text messages with Python for Free

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s