0

Hi I am trying to send mail with smtp.lib inside my python tkinter project,but I am getting an error and I cant seem to find a solution to this problem when trying to use my email. I have been trying and testing for days now.

Please let me know what I'm doing wrong and why I'm getting this error. The code below is below there.

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1131)

 
    
    for treeitems in list_of_lists:
        FILES = (treeitems[0])
        EMAILS = (treeitems[1])

        subject = subject_entry.get()
        body = Email_box.get("1.0","end")
        sender_email = Email_entry.get()
        receiver_email = EMAILS
        password = EPassword_entry.get()
        message = MIMEMultipart()
        message["From"] = sender_email
        message["To"] = receiver_email
        message["Subject"] = subject
        # message["Bcc"] = receiver_email 
        #addded this also the encode part
        message.attach(MIMEText(body, "plain"))
        filename = FILES  # In same directory as script

        with open(filename, "rb") as attachment:
            part = MIMEBase("application", "octet-stream")
            part.set_payload(attachment.read())       
            encoders.encode_base64(part)
            part.add_header(
            "Content-Disposition",
            f"attachment; filename= {filename}",)

            message.attach(part)
            text = message.as_string()

            context = ssl.create_default_context()
        with smtplib.SMTP_SSL(Server_entry.get(),Port_entry.get(), context=context) as server:
            server.login(sender_email, password)
            try:
                check_results = server.sendmail(sender_email, receiver_email, text)
            except smtplib.SMTPRecipientsRefused:
                     continue
            except smtplib.SMTPAuthenticationError:
                     continue
            except UnicodeEncodeError:
                     continue
            except ssl.SSLCertVerificationError:
                    continue
            check_list.append(check_results)
        for x in range(len(list_of_lists)):
            ProgBar["value"] = (len(check_list))
            root.update_idletasks()
            print(len(check_list))
            
    messagebox.showinfo("Report","Emails sent!")
    time.sleep(2)
   
    check_error_mails()
    time.sleep(1) ```
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Your error is `certificate has expired`. Your smtp server has an expired SSL certificate and needs to be updated. [This answer](https://stackoverflow.com/a/57333670/147356) may have a workaround that would allow you to continue despite the problematic certificate. – larsks Mar 02 '22 at 16:05

0 Answers0