forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomBulkEmailSender.py
50 lines (44 loc) · 1.57 KB
/
customBulkEmailSender.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import xlrd
import time
import smtplib
path = "selects.xlsx"
File = xlrd.open_workbook(path)
sheet = File.sheet_by_name('Selects')
mail_list = []
interviewerlist = []
name = []
for k in range(sheet.nrows - 1):
student = sheet.cell_value(k + 1, 0)
email = sheet.cell_value(k + 1, 1)
passed = sheet.cell_value(k + 1, 3)
interviewer = sheet.cell_value(k + 1, 4)
if passed == 'Yes':
mail_list.append(email)
interviewerlist.append(interviewer)
name.append(student)
email = 'example@gmail.com' # add the sender's email address
password = '*****' # sender's password
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email, password)
for mail_to in mail_list:
send_to_email = mail_to
find_des = mail_list.index(send_to_email)
studentName = name[find_des]
subject = f'Congratulations {studentName}!! You are selected for further interviews.'
message = f'Dear {studentName}, \n' \
f'We inform you that you wil be interviewed by ${interviewerlist[find_des]}. Please wait for the concern mail from your interviewer. \n'\
'\n' \
'Best Regards'
msg = MIMEMultipart()
msg['From '] = send_to_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
text = msg.as_string()
print(f'Sending email to {studentName}... ')
server.sendmail(email, send_to_email, text)
server.quit()
print('Mails sent!')
time.sleep(10)