def __sendmail(self, msg): """ Private method to actually send the message. @param msg the message to be sent (string) @return flag indicating success (boolean) """ try: server = smtplib.SMTP(Preferences.getUser("MailServer"), Preferences.getUser("MailServerPort")) if Preferences.getUser("MailServerUseTLS"): server.starttls() if Preferences.getUser("MailServerAuthentication"): # mail server needs authentication password = Preferences.getUser("MailServerPassword") if not password: password, ok = QInputDialog.getText( self, self.tr("Mail Server Password"), self.tr("Enter your mail server password"), QLineEdit.Password) if not ok: # abort return False try: server.login(Preferences.getUser("MailServerUser"), password) except (smtplib.SMTPException, socket.error) as e: if isinstance(e, smtplib.SMTPResponseException): errorStr = e.smtp_error.decode() elif isinstance(e, socket.error): errorStr = e[1] else: errorStr = str(e) res = E5MessageBox.retryAbort( self, self.tr("Send bug report"), self.tr( """<p>Authentication failed.<br>Reason: {0}</p>""") .format(errorStr), E5MessageBox.Critical) if res: return self.__sendmail(msg) else: return False QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() server.sendmail(Preferences.getUser("Email"), self.__toAddress, msg) server.quit() QApplication.restoreOverrideCursor() except (smtplib.SMTPException, socket.error) as e: QApplication.restoreOverrideCursor() if isinstance(e, smtplib.SMTPResponseException): errorStr = e.smtp_error.decode() elif isinstance(e, socket.error): errorStr = e[1] else: errorStr = str(e) res = E5MessageBox.retryAbort( self, self.tr("Send bug report"), self.tr( """<p>Message could not be sent.<br>Reason: {0}</p>""") .format(errorStr), E5MessageBox.Critical) if res: return self.__sendmail(msg) else: return False return True
def on_bTest_clicked(self): """ Private method to test the selected options. """ if self.rAbout.isChecked(): E5MessageBox.about( None, self.eCaption.text(), self.eMessage.toPlainText() ) elif self.rAboutQt.isChecked(): E5MessageBox.aboutQt( None, self.eCaption.text() ) elif self.rInformation.isChecked() or \ self.rQuestion.isChecked() or \ self.rWarning.isChecked() or \ self.rCritical.isChecked(): buttons = E5MessageBox.NoButton if self.abortCheck.isChecked(): buttons |= E5MessageBox.Abort if self.applyCheck.isChecked(): buttons |= E5MessageBox.Apply if self.cancelCheck.isChecked(): buttons |= E5MessageBox.Cancel if self.closeCheck.isChecked(): buttons |= E5MessageBox.Close if self.discardCheck.isChecked(): buttons |= E5MessageBox.Discard if self.helpCheck.isChecked(): buttons |= E5MessageBox.Help if self.ignoreCheck.isChecked(): buttons |= E5MessageBox.Ignore if self.noCheck.isChecked(): buttons |= E5MessageBox.No if self.notoallCheck.isChecked(): buttons |= E5MessageBox.NoToAll if self.okCheck.isChecked(): buttons |= E5MessageBox.Ok if self.openCheck.isChecked(): buttons |= E5MessageBox.Open if self.resetCheck.isChecked(): buttons |= E5MessageBox.Reset if self.restoreCheck.isChecked(): buttons |= E5MessageBox.RestoreDefaults if self.retryCheck.isChecked(): buttons |= E5MessageBox.Retry if self.saveCheck.isChecked(): buttons |= E5MessageBox.Save if self.saveallCheck.isChecked(): buttons |= E5MessageBox.SaveAll if self.yesCheck.isChecked(): buttons |= E5MessageBox.Yes if self.yestoallCheck.isChecked(): buttons |= E5MessageBox.YesToAll if buttons == E5MessageBox.NoButton: buttons = E5MessageBox.Ok defaultButton = self.buttonsCodeListBinary[ self.defaultCombo.currentIndex()] if self.rInformation.isChecked(): E5MessageBox.information( self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton ) elif self.rQuestion.isChecked(): E5MessageBox.question( self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton ) elif self.rWarning.isChecked(): E5MessageBox.warning( self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton ) elif self.rCritical.isChecked(): E5MessageBox.critical( self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton ) elif self.rYesNo.isChecked() or \ self.rRetryAbort.isChecked(): if self.iconInformation.isChecked(): icon = E5MessageBox.Information elif self.iconQuestion.isChecked(): icon = E5MessageBox.Question elif self.iconWarning.isChecked(): icon = E5MessageBox.Warning elif self.iconCritical.isChecked(): icon = E5MessageBox.Critical if self.rYesNo.isChecked(): E5MessageBox.yesNo( self, self.eCaption.text(), self.eMessage.toPlainText(), icon=icon, yesDefault=self.yesDefaultCheck.isChecked() ) elif self.rRetryAbort.isChecked(): E5MessageBox.retryAbort( self, self.eCaption.text(), self.eMessage.toPlainText(), icon=icon ) elif self.rOkToClearData.isChecked(): E5MessageBox.okToClearData( self, self.eCaption.text(), self.eMessage.toPlainText(), lambda: True )
def __sendmail(self, msg): """ Private method to actually send the message. @param msg the message to be sent (string) @return flag indicating success (boolean) """ try: encryption = Preferences.getUser("MailServerEncryption") if encryption == "SSL": server = smtplib.SMTP_SSL( Preferences.getUser("MailServer"), Preferences.getUser("MailServerPort")) else: server = smtplib.SMTP(Preferences.getUser("MailServer"), Preferences.getUser("MailServerPort")) if encryption == "TLS": server.starttls() if Preferences.getUser("MailServerAuthentication"): # mail server needs authentication password = Preferences.getUser("MailServerPassword") if not password: password, ok = QInputDialog.getText( self, self.tr("Mail Server Password"), self.tr("Enter your mail server password"), QLineEdit.Password) if not ok: # abort return False try: server.login(Preferences.getUser("MailServerUser"), password) except (smtplib.SMTPException, socket.error) as e: if isinstance(e, smtplib.SMTPResponseException): errorStr = e.smtp_error.decode() elif isinstance(e, OSError): errorStr = e.strerror elif isinstance(e, socket.error): errorStr = e[1] else: errorStr = str(e) res = E5MessageBox.retryAbort( self, self.tr("Send Message"), self.tr( """<p>Authentication failed.<br>Reason: {0}</p>""" ).format(errorStr), E5MessageBox.Critical) if res: return self.__sendmail(msg) else: return False QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() server.sendmail(Preferences.getUser("Email"), self.__toAddress, msg) server.quit() QApplication.restoreOverrideCursor() except (smtplib.SMTPException, socket.error) as e: QApplication.restoreOverrideCursor() if isinstance(e, smtplib.SMTPResponseException): errorStr = e.smtp_error.decode() elif isinstance(e, smtplib.SMTPException): errorStr = str(e) elif isinstance(e, socket.error): errorStr = e.strerror else: errorStr = str(e) res = E5MessageBox.retryAbort( self, self.tr("Send Message"), self.tr("""<p>Message could not be sent.<br>Reason: {0}</p>""" ).format(errorStr), E5MessageBox.Critical) if res: return self.__sendmail(msg) else: return False return True
def on_bTest_clicked(self): """ Private method to test the selected options. """ if self.rAbout.isChecked(): E5MessageBox.about(None, self.eCaption.text(), self.eMessage.toPlainText()) elif self.rAboutQt.isChecked(): E5MessageBox.aboutQt(None, self.eCaption.text()) elif self.rInformation.isChecked() or \ self.rQuestion.isChecked() or \ self.rWarning.isChecked() or \ self.rCritical.isChecked(): buttons = E5MessageBox.NoButton if self.abortCheck.isChecked(): buttons |= E5MessageBox.Abort if self.applyCheck.isChecked(): buttons |= E5MessageBox.Apply if self.cancelCheck.isChecked(): buttons |= E5MessageBox.Cancel if self.closeCheck.isChecked(): buttons |= E5MessageBox.Close if self.discardCheck.isChecked(): buttons |= E5MessageBox.Discard if self.helpCheck.isChecked(): buttons |= E5MessageBox.Help if self.ignoreCheck.isChecked(): buttons |= E5MessageBox.Ignore if self.noCheck.isChecked(): buttons |= E5MessageBox.No if self.notoallCheck.isChecked(): buttons |= E5MessageBox.NoToAll if self.okCheck.isChecked(): buttons |= E5MessageBox.Ok if self.openCheck.isChecked(): buttons |= E5MessageBox.Open if self.resetCheck.isChecked(): buttons |= E5MessageBox.Reset if self.restoreCheck.isChecked(): buttons |= E5MessageBox.RestoreDefaults if self.retryCheck.isChecked(): buttons |= E5MessageBox.Retry if self.saveCheck.isChecked(): buttons |= E5MessageBox.Save if self.saveallCheck.isChecked(): buttons |= E5MessageBox.SaveAll if self.yesCheck.isChecked(): buttons |= E5MessageBox.Yes if self.yestoallCheck.isChecked(): buttons |= E5MessageBox.YesToAll if buttons == E5MessageBox.NoButton: buttons = E5MessageBox.Ok defaultButton = self.buttonsCodeListBinary[ self.defaultCombo.currentIndex()] if self.rInformation.isChecked(): E5MessageBox.information(self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton) elif self.rQuestion.isChecked(): E5MessageBox.question(self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton) elif self.rWarning.isChecked(): E5MessageBox.warning(self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton) elif self.rCritical.isChecked(): E5MessageBox.critical(self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton) elif self.rYesNo.isChecked() or \ self.rRetryAbort.isChecked(): if self.iconInformation.isChecked(): icon = E5MessageBox.Information elif self.iconQuestion.isChecked(): icon = E5MessageBox.Question elif self.iconWarning.isChecked(): icon = E5MessageBox.Warning elif self.iconCritical.isChecked(): icon = E5MessageBox.Critical if self.rYesNo.isChecked(): E5MessageBox.yesNo(self, self.eCaption.text(), self.eMessage.toPlainText(), icon=icon, yesDefault=self.yesDefaultCheck.isChecked()) elif self.rRetryAbort.isChecked(): E5MessageBox.retryAbort(self, self.eCaption.text(), self.eMessage.toPlainText(), icon=icon) elif self.rOkToClearData.isChecked(): E5MessageBox.okToClearData(self, self.eCaption.text(), self.eMessage.toPlainText(), lambda: True)