Skip to content

Instantly share code, notes, and snippets.

@AO8
Created September 19, 2020 16:13
Show Gist options
  • Save AO8/6ff8f63cdaafcd968bf14224221b96f2 to your computer and use it in GitHub Desktop.
Save AO8/6ff8f63cdaafcd968bf14224221b96f2 to your computer and use it in GitHub Desktop.
For Susan.
# be sure to enable less secure apps in gmail
import smtplib
import ssl
from email.mime.text import MIMEText
def send_gmail(sender, password, receiver, subject, body):
"""Prepare and send a nicely formatted Gmail"""
msg = MIMEText(body)
msg["Subject"] = subject
msg["From"] = sender
msg["To"] = receiver
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as s:
s.login(sender, password)
s.sendmail(sender, receiver, msg.as_string())
filename = # your_csv_file.csv
my_gmail = input("Enter your Gmail address: ").strip()
my_password = input("Enter your Gmail password: ").strip()
my_data = []
with open(filename, encoding="utf-8") as f:
for line in f.readlines():
data = line.strip().split(",")
my_data.append((data[0], data[1]))
for code, student in my_data:
send_gmail(my_gmail,
my_password,
student,
"IMPORTANT Big Java Etext Rental Access Code for SDEV 301",
f"Here is your code: {code}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment