Методы класса электронной почты вылетает из моего GUI. Хотя я получаю почту, но мой GUI падает - PullRequest
0 голосов
/ 19 сентября 2019

Когда этот метод вызывается из контроллера, мой GUI падает, я понятия не имею, почему это происходит, хотя я получаю электронные письма.Когда я неожиданно вызываю метод смены пароля, мой GUI падает.

class Email(object):
    """Takes an email ID for for receiving
    the 6-digit code sent by the Super Mart
    for recovery purpose of Admin Account"""

    def __init__(self, receiving, name, username):
        """Object must have the email of receiver
        and the full of the receiver"""
        try:
            self.username = username
            self.receiver = []
            self.receiver.append(receiving)
            self.email_id = os.environ.get('mart_id')
            self.id_pass = os.environ.get('mart_code')
            # Sending a copy of Code Generated to Admin
            self.receiver.append(self.email_id)
            self.name = name
            self.pin = Email.code()
        except Exception as error:
            print(error)
        else:
            print("OKAY")

    def pass_change(self):
        """This generates e mail when when a user changes
        the password"""
        try:
            message = EmailMessage()
            message['Subject'] = 'Password Changed'
            message['From'] = "Super Mart"
            # if there are more than one recipients we may have a list of recipients
            # Now for testing purpose i have sent email to my account for confirmation
            message['to'] = self.receiver
            message.set_content("Recovery main")
            message.add_alternative("""\
                   <!DOCTYPE html>
                           <html>
                           <head>
                               <title>
                            </title>
                           </head>
                           <body>
                            <h1 style="color:black;">
                                Hello """ + self.name + """,<br>    </h1>

                                <h3>Your Request For change of password is approved, your password is succesfully updated. <br></h3>
                            <h4><strong>Username : """ + self.username + """</strong></h4>
                            <p>If this activity was not done by you please recover your account as soon as possible<p>

                            <p>Please keep Your password and username  safe and dont tell it to any one else.
                            This code  is confidential. 
                            It is strictly forbidden to share any part of this message with any third person.</p>

                           </body>
                           </html>
                           """, subtype='html')
            try:
                with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
                    # Used to log in
                    try:
                        smtp.login(self.email_id, self.id_pass)
                        # USed for sending mail
                        smtp.send_message(message)
                    except Exception as error:
                        print("LOLZ")
                        print(error)
                    else:
                        print(" ALL FINE")
            except:
                print("LAG GAE")
        except Exception as error:
            print(error)
            print("LOLZ")
        else:
            print("All okay")
            return 1
...