0

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()
Luca
  • 160
  • 3
  • 14
  • You need to show the code to get an answer about what the problem is. – match Jan 13 '18 at 16:22
  • @match I've done – Luca Jan 13 '18 at 16:36
  • I'm thinking that the reason is that process is too busy to elaborate other things, I can't understand why windows think that my program is not running – Luca Jan 13 '18 at 16:40
  • 1
    It would be useful to see how this method is called from the main GUI - though I suspect this is down to the GUI event loop waiting for this method to return, and you'll need to figure out how to fire it off as a background process/thread, depending on what UI toolkit you are using. – match Jan 13 '18 at 16:54

0 Answers0