-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailSender.py
315 lines (299 loc) · 16.8 KB
/
mailSender.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'GUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import webbrowser, os, re
import csv
import smtplib,os,sys,imghdr
from email.message import EmailMessage
import urllib.request
base_dir = os.getcwd()
regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
os.system("cmd /c pip install PyQt5")
def check(email):
if (re.search(regex, email)):
return True
else:
return False
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1053, 1037)
MainWindow.setStyleSheet("background-color: rgb(43, 43, 43);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.emailID = QtWidgets.QTextEdit(self.centralwidget)
self.emailID.setGeometry(QtCore.QRect(230, 20, 771, 31))
self.emailID.setStyleSheet("background-color: rgb(60, 63, 65);\n"
"color: rgb(170, 255, 0); border: none;")
self.emailID.setObjectName("emailID")
self.pwd = QtWidgets.QLineEdit(self.centralwidget)
self.pwd.setGeometry(QtCore.QRect(230, 80, 771, 31))
self.pwd.setEchoMode(QtWidgets.QLineEdit.Password)
self.pwd.setStyleSheet("background-color: rgb(60, 63, 65);\n"
"color: rgb(170, 255, 0); border: none;")
self.pwd.setObjectName("pwd")
self.labelFrame = QtWidgets.QFrame(self.centralwidget)
self.labelFrame.setGeometry(QtCore.QRect(20, 10, 201, 451))
font = QtGui.QFont()
font.setFamily("Adobe Gurmukhi")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.labelFrame.setFont(font)
self.labelFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.labelFrame.setFrameShadow(QtWidgets.QFrame.Raised)
self.labelFrame.setObjectName("labelFrame")
self.labelEmail = QtWidgets.QLabel(self.labelFrame)
self.labelEmail.setGeometry(QtCore.QRect(20, 10, 161, 31))
self.labelEmail.setStyleSheet("color: rgb(255, 255, 255);")
self.labelEmail.setObjectName("labelEmail")
self.labelPassword = QtWidgets.QLabel(self.labelFrame)
self.labelPassword.setGeometry(QtCore.QRect(20, 75, 121, 21))
self.labelPassword.setStyleSheet("color: rgb(255, 255, 255);\n"
"border-color: rgb(170, 255, 0);")
self.labelPassword.setObjectName("labelPassword")
self.labelSheet = QtWidgets.QLabel(self.labelFrame)
self.labelSheet.setGeometry(QtCore.QRect(20, 360, 101, 31))
self.labelSheet.setStyleSheet("color: rgb(255, 255, 255);")
self.labelSheet.setObjectName("labelSheet")
self.labelContent = QtWidgets.QLabel(self.labelFrame)
self.labelContent.setGeometry(QtCore.QRect(20, 420, 101, 31))
self.labelContent.setStyleSheet("color: rgb(255, 255, 255);")
self.labelContent.setObjectName("labelContent")
self.labelGreet = QtWidgets.QLabel(self.labelFrame)
self.labelGreet.setGeometry(QtCore.QRect(20, 180, 151, 41))
self.labelGreet.setStyleSheet("color: rgb(255, 255, 255);")
self.labelGreet.setObjectName("labelGreet")
self.labelSubject = QtWidgets.QLabel(self.labelFrame)
self.labelSubject.setGeometry(QtCore.QRect(21, 122, 111, 41))
self.labelSubject.setStyleSheet("color: rgb(255, 255, 255);")
self.labelSubject.setObjectName("labelSubject")
self.labelAttachment = QtWidgets.QLabel(self.labelFrame)
self.labelAttachment.setGeometry(QtCore.QRect(20, 300, 101, 31))
self.labelAttachment.setStyleSheet("color: rgb(255, 255, 255);")
self.labelAttachment.setObjectName("labelAttachment")
self.send = QtWidgets.QPushButton(self.centralwidget)
self.send.setGeometry(QtCore.QRect(810, 950, 171, 41))
self.send.setStyleSheet("background-color: rgb(0, 228, 232);\n"
"background-color: qlineargradient(spread:pad, x1:0.995025, y1:0.563, x2:0, y2:0.545909, stop:0 rgba(98, 170, 70, 255), stop:1 rgba(255, 255, 255, 255));\n"
"color: rgb(0, 0, 0); border-radius: 15px;")
self.send.setObjectName("send")
self.abort = QtWidgets.QPushButton(self.centralwidget)
self.abort.setGeometry(QtCore.QRect(70, 950, 151, 41))
self.abort.setStyleSheet("background-color: rgb(0, 228, 232);\n"
"background-color: qlineargradient(spread:pad, x1:0, y1:0.54, x2:1, y2:0.58, stop:0 rgba(98, 170, 70, 255), stop:1 rgba(255, 255, 255, 255));\n"
"color: rgb(0, 0, 0); border-radius: 15px;")
self.abort.setObjectName("abort")
self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
self.progressBar.setGeometry(QtCore.QRect(30, 540, 1001, 31))
self.progressBar.setProperty("value", 0)
self.progressBar.setStyleSheet("color: rgb(255, 255, 255)")
self.progressBar.setObjectName("progressBar")
self.sheetDisplay = QtWidgets.QTextBrowser(self.centralwidget)
self.sheetDisplay.setGeometry(QtCore.QRect(230, 370, 601, 31))
self.sheetDisplay.setStyleSheet("background-color: rgb(60, 63, 65);\n"
"color: rgb(170, 255, 0);border: none;")
self.sheetDisplay.setObjectName("sheetDisplay")
self.contentDisplay = QtWidgets.QTextBrowser(self.centralwidget)
self.contentDisplay.setGeometry(QtCore.QRect(230, 430, 601, 31))
self.contentDisplay.setStyleSheet("background-color: rgb(60, 63, 65);\n"
"color: rgb(170, 255, 0);border: none;")
self.contentDisplay.setObjectName("contentDisplay")
self.labelSecure = QtWidgets.QLabel(self.centralwidget)
self.labelSecure.setGeometry(QtCore.QRect(540, 480, 311, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.labelSecure.setFont(font)
self.labelSecure.setStyleSheet("color: rgb(255, 255, 255);")
self.labelSecure.setObjectName("labelSecure")
self.buttonFrame = QtWidgets.QFrame(self.centralwidget)
self.buttonFrame.setGeometry(QtCore.QRect(850, 290, 181, 231))
font = QtGui.QFont()
font.setFamily("Segoe UI Symbol")
font.setPointSize(10)
self.buttonFrame.setFont(font)
self.buttonFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.buttonFrame.setFrameShadow(QtWidgets.QFrame.Raised)
self.buttonFrame.setObjectName("buttonFrame")
self.browser = QtWidgets.QPushButton(self.buttonFrame)
self.browser.setGeometry(QtCore.QRect(10, 190, 151, 31))
self.browser.setStyleSheet("background-color: rgb(0, 228, 232);\n"
"background-color: qlineargradient(spread:pad, x1:0, y1:0.551636, x2:0.995025, y2:0.563, stop:0 rgba(244, 148, 167, 255), stop:1 rgba(255, 255, 255, 255));\n"
"color: rgb(0, 0, 0); border-radius: 15px;")
self.browser.setObjectName("browser")
self.uploadContent = QtWidgets.QPushButton(self.buttonFrame)
self.uploadContent.setGeometry(QtCore.QRect(10, 140, 151, 31))
self.uploadContent.setStyleSheet("background-color: rgb(0, 228, 232);\n"
"background-color: qlineargradient(spread:pad, x1:0, y1:0.54, x2:1, y2:0.58, stop:0 rgba(0, 220, 224, 255), stop:1 rgba(255, 255, 255, 255));\n"
"color: rgb(0, 0, 0); border-radius: 15px;")
self.uploadContent.setObjectName("uploadContent")
self.uploadSheet = QtWidgets.QPushButton(self.buttonFrame)
self.uploadSheet.setGeometry(QtCore.QRect(10, 80, 151, 31))
self.uploadSheet.setStyleSheet("background-color: rgb(0, 228, 232);\n"
"border-color: rgb(85, 255, 255);\n"
"background-color: qlineargradient(spread:pad, x1:0, y1:0.54, x2:1, y2:0.58, stop:0 rgba(0, 220, 224, 255), stop:1 rgba(255, 255, 255, 255));\n"
"color: rgb(0, 0, 0); border-radius: 15px;")
self.uploadSheet.setObjectName("uploadSheet")
self.pushAttachment = QtWidgets.QPushButton(self.buttonFrame)
self.pushAttachment.setGeometry(QtCore.QRect(10, 20, 151, 31))
self.pushAttachment.setGeometry(QtCore.QRect(10, 20, 151, 31))
self.pushAttachment.setStyleSheet("background-color: rgb(0, 228, 232);\n"
"background-color: qlineargradient(spread:pad, x1:0, y1:0.54, x2:1, y2:0.58, stop:0 rgba(0, 220, 224, 255), stop:1 rgba(255, 255, 255, 255));\n"
"color: rgb(0, 0, 0); border-radius: 15px;")
self.pushAttachment.setObjectName("pushAttachment")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(20, 590, 1021, 331))
font = QtGui.QFont()
font.setFamily("Solid Edge ANSI Unicode")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.groupBox.setFont(font)
self.groupBox.setStyleSheet("color: rgb(255, 255, 255);\n"
"border-color: rgb(170, 255, 0);")
self.groupBox.setObjectName("groupBox")
self.message = QtWidgets.QTextBrowser(self.groupBox)
self.message.setGeometry(QtCore.QRect(10, 30, 1001, 291))
self.message.setLayoutDirection(QtCore.Qt.LeftToRight)
self.message.setStyleSheet("background-color: rgb(60, 63, 65);\n"
"color: rgb(170, 255, 0);")
self.message.setObjectName("message")
self.textGreet = QtWidgets.QTextEdit(self.centralwidget)
self.textGreet.setGeometry(QtCore.QRect(230, 200, 771, 31))
self.textGreet.setStyleSheet("background-color: rgb(60, 63, 65);\n"
"color: rgb(170, 255, 0); border: none;")
self.textGreet.setObjectName("textGreet")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(233, 245, 561, 51))
self.label.setStyleSheet("color: rgb(255, 255, 255);")
self.label.setObjectName("label")
self.textSubject = QtWidgets.QTextEdit(self.centralwidget)
self.textSubject.setGeometry(QtCore.QRect(230, 140, 771, 31))
self.textSubject.setStyleSheet("background-color: rgb(60, 63, 65);\n"
"color: rgb(170, 255, 0); border: none;")
self.textSubject.setObjectName("textSubject")
self.textAttachment = QtWidgets.QTextBrowser(self.centralwidget)
self.textAttachment.setGeometry(QtCore.QRect(230, 310, 601, 31))
self.textAttachment.setStyleSheet("background-color: rgb(60, 63, 65);\n"
"color: rgb(170, 255, 0); border: none;")
self.textAttachment.setObjectName("textAttachment")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(360, 960, 321, 31))
font = QtGui.QFont()
font.setFamily("Segoe Print")
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setStyleSheet("color: rgb(255, 255, 255);")
self.label_2.setObjectName("label_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1053, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.browser.clicked.connect(lambda: webbrowser.open(
'https://myaccount.google.com/u/5/lesssecureapps?pli=1&rapt=AEjHL4MeMmZUv6RIXz5qdrt_62ZLncG2AiL0sCreZfc_-5DkJAFl-GzqJE7twChLQV8S4yG2U4JvO9Oi2-YD9YGYV0p3QPwBOg'))
self.uploadSheet.clicked.connect(self.csvUpload)
self.uploadContent.clicked.connect(self.contentUpload)
self.send.clicked.connect(self.sendMails)
self.pushAttachment.clicked.connect(self.fileUpload)
self.attachFile = None
def sendMails(self):
self.message.clear()
emailID = self.emailID.toPlainText()
pwd = self.pwd.text()
subject = self.textSubject.toPlainText()
greet = self.textGreet.toPlainText()
if len(greet) == 0:
greet = "Respected"
if check(emailID):
if len(pwd) == 0:
self.message.append("Enter Password.")
else:
self.message.append("Email address : " + emailID + "\n")
file_1 = open(self.csv_name)
total_rows = len(file_1.readlines())
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(emailID, pwd)
count = 0
with open(self.csv_name, 'r') as file:
reader = csv.reader(file)
for row in reader:
self.message.append("Email Id : " + row[0] + "; Name : " + row[1])
msg = EmailMessage()
msg['Subject'] = subject
msg['From'] = emailID
msg['To'] = row[0]
con = open(self.content_name, "r+")
msg_content = greet + " " + row[1] + ",\n\n" + con.read()
msg.set_content(msg_content)
if self.attachFile != None:
with open(self.attachFile, 'rb') as f:
file_data = f.read()
file_type = imghdr.what(f.name)
file_name = os.path.basename(self.attachFile)
msg.add_attachment(file_data, maintype='image', subtype=file_type, filename=file_name)
smtp.send_message(msg)
count = count + 1
print("Count: " + str(count) + " Email Id : " + row[0] + "; Name : " + row[1])
self.message.append("Sent")
self.progressUpdate((count / total_rows) * 100)
# print("mail has been sent to candidate no. {count} {file} \n".format(count=count,file=file[:-4]))
self.message.append(
"all emails have been successfully delivered to {count} candidates".format(count=count))
else:
self.message.append("Invalid Email Address.")
def progressUpdate(self, value):
value = int(value)
self.progressBar.setValue(value)
def csvUpload(self):
self.csv_name = QtWidgets.QFileDialog.getOpenFileName(None, 'Open files', base_dir, "CSV file(*.csv)")[0]
self.sheetDisplay.setText(self.csv_name)
def contentUpload(self):
self.content_name = QtWidgets.QFileDialog.getOpenFileName(None, 'Open files', base_dir, "TXT file(*.txt)")[0]
self.contentDisplay.setText(self.content_name)
def fileUpload(self):
self.attachFile = QtWidgets.QFileDialog.getOpenFileName(None, 'Open files', base_dir, "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png)")[0]
self.textAttachment.setText(self.attachFile)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Email Iterator"))
urllib.request.urlretrieve(
"https://iconarchive.com/download/i75211/cornmanthe3rd/metronome/Communication-email-blue.ico",
"sample.ico")
MainWindow.setWindowIcon(QtGui.QIcon('sample.ico'))
self.labelEmail.setText(_translate("MainWindow", "Email Address"))
self.labelPassword.setText(_translate("MainWindow", "Password"))
self.labelSheet.setText(_translate("MainWindow", "Sheet File"))
self.labelContent.setText(_translate("MainWindow", "Content File"))
self.labelGreet.setText(_translate("MainWindow", "Greeting Message"))
self.labelSubject.setText(_translate("MainWindow", "Subject"))
self.labelAttachment.setText(_translate("MainWindow", "Attachment"))
self.send.setText(_translate("MainWindow", "Send"))
self.abort.setText(_translate("MainWindow", "Abort"))
self.labelSecure.setText(_translate("MainWindow", "Turn on Less Secure App Access"))
self.browser.setText(_translate("MainWindow", "Click"))
self.uploadContent.setText(_translate("MainWindow", "Upload"))
self.uploadSheet.setText(_translate("MainWindow", "Upload"))
self.pushAttachment.setText(_translate("MainWindow", "Upload"))
self.groupBox.setTitle(_translate("MainWindow", "Statistic"))
self.label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:9pt;\">Default : Respected</span></p><p><span style=\" font-size:9pt;\">e.g., Respected Krishna,</span><br/></p></body></html>"))
self.label_2.setText(_translate("MainWindow", "©2021 KK All rights reserved"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
MainWindow.showMaximized()
sys.exit(app.exec_())