forked from Somsubhra1/Hacktoberfest2k20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Email bot.py
104 lines (51 loc) · 1.9 KB
/
Email bot.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# This email bot is made by Aayush Patil
# Email bot
# Follow me insta ayush_patil7
import smtplib
import config
import xlrd
import socket
# Explain why we have to do this
socket.getaddrinfo('localhost', 25)
loc = 'Emails.xlsx'
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
class Sending_emails:
def __init__(self, username, password, subject, msg):
self.username = username
self.password = password
self.subject = subject
self.msg = msg
def send_email(self):
for all_emails in range(sheet.nrows):
try:
print("Target set : {0}".format(sheet.cell_value(all_emails + 1, 0)))
except IndexError:
None
try:
print("We are sending email to {0}".format(sheet.cell_value(all_emails + 1, 0)))
except IndexError:
None
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(self.username, self.password)
message = 'Subject: {}\n\n{}'.format(sheet.cell_value(all_emails + 1, 2),
sheet.cell_value(all_emails + 1, 1))
try:
server.sendmail(self.username, sheet.cell_value(all_emails + 1, 0), message)
except IndexError:
None
server.quit()
print("Email sent to: {0} ".format(sheet.cell_value(all_emails + 1, 0)))
count = 0
while count < 200:
try:
e = Sending_emails(config.EMAIL_ADDRESS, config.PASSWORD, sheet.cell_value(count + 1, 2),
sheet.cell_value(count + 1, 1))
e.send_email()
count = count + 1
except IndexError:
print("Done with sending emails")
print("Congratulations we have send emails successfully")
break