Skip to content

Instantly share code, notes, and snippets.

@MaddoxRauch
Created December 7, 2021 02:29
Show Gist options
  • Save MaddoxRauch/6856acfa38dc209acff7ae73acaad751 to your computer and use it in GitHub Desktop.
Save MaddoxRauch/6856acfa38dc209acff7ae73acaad751 to your computer and use it in GitHub Desktop.
Send text messages using email servers and SMS gateways.
import smtplib
def send(message: str, username: str, password: str, phone: str) -> None:
"""Sends messages to phone using Gmail servers."""
# Some SMS gateways may be outdated or different, i.e. @txt.att.net was @sms.att.net
carriers = {
'att': '@txt.att.net',
'tmobile': '@tmomail.net',
'verizon': '@vtext.com',
'sprint': '@page.nextel.com'
}
# Replace the number with your own, or consider using an argument\dict for multiple people.
to_number = '{}{}'.format(phone, carriers['att'])
auth = (username, password)
# Establish a secure session with gmail's outgoing SMTP server using your gmail account
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(auth[0], auth[1])
# Send text message through SMS gateway of destination number
server.sendmail(auth[0], to_number, message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment