How to send text messages with Python for Free

David Mentgen
TestingOnProd
Published in
2 min readOct 24, 2021

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:

  • Python (I used version 3.9.1)
  • smtplib (https://docs.python.org/3/library/smtplib.html)
  • Email (I use gmail)

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: https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=637700239874464736-1954441174&rd=1

Code

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 PythonTextMessage.py 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.

Conclusion

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!

Originally published at http://testingonprod.com on October 24, 2021.

--

--