Skip to content

Instantly share code, notes, and snippets.

@sumanthratna
Last active July 22, 2019 01:09
Show Gist options
  • Save sumanthratna/8040523b78d40a12854c0142daf860fc to your computer and use it in GitHub Desktop.
Save sumanthratna/8040523b78d40a12854c0142daf860fc to your computer and use it in GitHub Desktop.
A Python script to send messages from a GMail account to an email account or phone number.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
Type = input("Enter 1 for eMail, 2 for SMS: ")
toaddr = 0
if Type == '1':
toaddr = input("Enter to address: ")
else:
Provider = input("1 for Sprint, 2 for AT&T, and 3 for Verizon: ")
Mobile = input("Enter the mobile number: ")
if Provider == '1':
toaddr = str(Mobile) + "@messaging.sprintpcs.com"
if Provider == '2':
toaddr = str(Mobile) + '@txt.att.net'
if Provider == '3':
toaddr = str(Mobile) + '@tmomail.net'
head = input("Enter your subject: ")
body = input("Enter your message: ")
fromaddr = input("Enter the 'From Address'(example@gmail.com): ")
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = head
password = input("Enter the from address password: ")
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, password)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
print("Your message was sent")
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment