Warlord-K commited on
Commit
26b5643
1 Parent(s): af782b7

Add Mailing Code

Browse files
Files changed (1) hide show
  1. mailer.py +37 -0
mailer.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import smtplib, ssl
2
+ import datetime
3
+
4
+ def send_mails(ids):
5
+ all_mails = [f"cse22000100{i}" for i in range (1, 10)] + [f"cse2200010{i}" for i in range (10, 84)]
6
+ port = 587 # For starttls
7
+ smtp_server = "smtp.gmail.com"
8
+ sender_email = "contactkhelogames@gmail.com"
9
+ password = open("password.txt", "r").read()
10
+ # receiver_email = "cse210001083@iiti.ac.in"
11
+ message_present = f"""\
12
+ Subject: Attendace for {datetime.date.today()}
13
+ Your attendance for the class has been marked present."""
14
+ message_absent = f"""\
15
+ Subject: Attendace for {datetime.date.today()}
16
+ Your attendance for the class has been marked absent."""
17
+ for receiver_email in ids:
18
+ context = ssl.create_default_context()
19
+ with smtplib.SMTP(smtp_server, port) as server:
20
+ server.ehlo()
21
+ server.starttls(context=context)
22
+ server.ehlo()
23
+ server.login(sender_email, password)
24
+ server.sendmail(sender_email, receiver_email, message_present)
25
+ print(f"Mail sent to {receiver_email}")
26
+ all_mails.remove(receiver_email)
27
+
28
+ for receiver_email in all_mails:
29
+ context = ssl.create_default_context()
30
+ with smtplib.SMTP(smtp_server, port) as server:
31
+ server.ehlo()
32
+ server.starttls(context=context)
33
+ server.ehlo()
34
+ server.login(sender_email, password)
35
+ server.sendmail(sender_email, receiver_email, message_absent)
36
+ print(f"Mail sent to {receiver_email}")
37
+ print("All mails sent successfully")