Last active
March 1, 2022 08:29
-
-
Save rotated8/4746555 to your computer and use it in GitHub Desktop.
Send emails through Gmail with Python. Send text messages using the SMS gateways. If you use Gmail's two-factor authentication, you'll need to set up an application specific password.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gmail_username = 'username@gmail.com' | |
recipients = 'recipient@example.com' | |
# https://en.wikipedia.org/wiki/List_of_SMS_gateways | |
# 10DigitNumber@text.att.net for AT&T | |
# 10DigitNumber@vtext.com for Verizon | |
from email.mime.text import MIMEText | |
msg = MIMEText('This is the body of the message.') | |
msg['Subject'] = 'Blank subject lines look like spam.' | |
msg['From'] = gmail_username | |
msg['To'] = recipients | |
msg = msg.as_string() | |
import smtplib | |
session = smtplib.SMTP('smtp.gmail.com', 587) | |
session.ehlo() | |
session.starttls() | |
session.login(gmail_username, 'your-gmail-or-application-specific-password') | |
session.sendmail(gmail_username, recipients, msg) | |
session.quit() |
server.sendmail(gmail_username, recipients, msg)
NameError: name 'server' is not defined
Whoops, should be 'session'.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for tmobile, it is 10DigitNum@tmomail.net