CSE-26-Attendance / mailer.py
Warlord-K's picture
Add Mailing Code
26b5643
import smtplib, ssl
import datetime
def send_mails(ids):
all_mails = [f"cse22000100{i}" for i in range (1, 10)] + [f"cse2200010{i}" for i in range (10, 84)]
port = 587 # For starttls
smtp_server = "smtp.gmail.com"
sender_email = "contactkhelogames@gmail.com"
password = open("password.txt", "r").read()
# receiver_email = "cse210001083@iiti.ac.in"
message_present = f"""\
Subject: Attendace for {datetime.date.today()}
Your attendance for the class has been marked present."""
message_absent = f"""\
Subject: Attendace for {datetime.date.today()}
Your attendance for the class has been marked absent."""
for receiver_email in ids:
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo()
server.starttls(context=context)
server.ehlo()
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message_present)
print(f"Mail sent to {receiver_email}")
all_mails.remove(receiver_email)
for receiver_email in all_mails:
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo()
server.starttls(context=context)
server.ehlo()
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message_absent)
print(f"Mail sent to {receiver_email}")
print("All mails sent successfully")