-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusing_csv.py
30 lines (24 loc) · 919 Bytes
/
using_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import csv, smtplib, ssl,getpass
port = 465 #for SSL
smtp_server = "smtp.gmail.com" #using gmail smtp server
message = """Subject: Your grade
Hi {name}, your grade is {grade}"""
from_address = "[email protected]"
password = getpass.getpass(prompt='Password: ', stream=None)
"""
Note: csv file consists of dummy emails.
So kindly replace with the mails you prefer or want to send mails to
"""
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server,port,context=context) as server:
server.login("[email protected]",password)
with open("Projects/Mail/dummy.csv") as file:
reader = csv.reader(file)
next(reader) #skipping next row
for name,email,grade in reader:
print(f"Sending mail to {name}... ")
server.sendmail(
from_address,
email,
message.format(name=name,grade=grade),
)