0

I am developing a PyQt application that sends mails. It reads the authentication information from a file. I'm trying to check if the authentication is ok before calling initUI() and to display an error message and exit the whole app if it doens't.

This is a fragment of my code :

class Mailer(QWidget):
    def __init__(self):
        super().__init__()

        config = configparser.ConfigParser()
        config.read('config.ini')

        self.server = config["SMTP SERVER"]
        self.user = config["USER"]
        self.smtpServer = smtplib.SMTP_SSL(self.server["Host"],self.server["Port"])

        try:
            self.smtpServer.login(self.user["Username"],self.user["Password"])
            self.smtpServer.quit()
        except smtplib.SMTPAuthenticationError:
            QMessageBox.critical(self, "Error de autenticación", """El usuario y/o la contraseña en el archivo config.ini son incorrectos.""", QMessageBox.Ok)
            QCoreApplication.instance().quit()

        self.initUI()

The problem is that it doesn't exit the application. If I change QCoreApplication.instance().quit() by self.close() I get the same.

Olivier Giniaux
  • 870
  • 2
  • 8
  • 22
lembon
  • 125
  • 7
  • Surely `self.smtpServer.quit()` should go inside the `except` block? – ekhumoro Jun 26 '15 at 20:55
  • That's true, I thought the SMTP Initializator didn't start a connection and it was the `login()` function which did it. Thank you. – lembon Jun 28 '15 at 01:24

1 Answers1

0

Have you tried sys.exit(0) ? (You need import sys for this, but you probably imported it already as it is required for pyqt sys.exit(app.exec_()))

If it doesn't work, I believe that your problem comes from somewhere else.

Olivier Giniaux
  • 870
  • 2
  • 8
  • 22