I made a program to send email with attachment.
While the program is loading the files to be attached, the gui stops responding and Windows changes the window status to 'not responding', but when it has finished loading the files everything is back working. I wonder if there is a way to prevent Windows from changing the state, thanks in advance.
Code:
def send_mail(self, send_to, files=[]):
msg = MIMEMultipart()
msg['From'] = self.programData['name']
msg['To'] = ''
msg['Date'] = formatdate(localtime = True)
msg['Subject'] = self.programData['name']
txt = self.programData['emailText']
text = txt
msg.attach(MIMEText(text))
for path in files:
part = MIMEBase('application', "octet-stream")
with open(path, 'rb') as file:
part.set_payload(file.read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="{0}"'.format(os.path.basename(path)))
msg.attach(part)
smtp = smtplib.SMTP('smtp.gmail.com', 587)
smtp.starttls()
smtp.login('user','passw')
smtp.sendmail('sender', send_to, msg.as_string())
smtp.quit()