def sending(self): if self.email.text() == '': msg = QMessageBox(self) msg.setText(LANGUAGE("wrong3")) msg.setIcon(QMessageBox.Critical) msg.setWindowTitle(LANGUAGE("mistake")) msg.setFont(QFont("Times New Roman", 14)) x = msg.exec_() elif self.question.toPlainText() == '': msg = QMessageBox(self) msg.setIcon(QMessageBox.Critical) msg.setText(LANGUAGE("wrong2")) msg.setWindowTitle(LANGUAGE("mistake")) msg.setFont(QFont("Times New Roman", 14)) x = msg.exec_() else: try: addr_from = '*****@*****.**' password = '******' server = smtplib.SMTP('smtp.yandex.ru', 587) server.ehlo() server.starttls() server.login(addr_from, password) addr_to = self.email.text() msg = MIMEMultipart() msg['From'] = addr_from msg['To'] = addr_to msg['Subject'] = 'Подтверждение' body = 'Здравствуйте! \n' \ 'Мы получили Ваше сообщение и ответим в течение 3-х рабочих дней.\n\n' \ 'С уважением, команда разработчиков.' msg.attach(MIMEText(body, 'plain')) server.send_message(msg) msg = MIMEMultipart() msg['From'] = addr_from msg['To'] = addr_from msg['Subject'] = 'Новый вопрос' body = f'Получен новый вопрос.\nОтправитель: {addr_to}\n' \ f'Текст: "{self.question.toPlainText()}"' msg.attach(MIMEText(body, 'plain')) path_report = 'reports/report.json' with open(path_report, 'rb') as report: part = MIMEApplication( report.read(), name=basename(path_report) ) part['Content-Disposition'] = 'attachment; filename="%s"' % basename(path_report) msg.attach(part) server.send_message(msg) server.quit() msg = QMessageBox(self) msg.setText(LANGUAGE("send_request")) msg.setWindowTitle(LANGUAGE("title_success")) msg.setFont(QFont("Times New Roman", 14)) x = msg.exec_() self.close() except Exception as e: msg = QMessageBox(self) msg.setText(LANGUAGE("wrong1")) msg.setIcon(QMessageBox.Critical) msg.setWindowTitle(LANGUAGE("mistake")) msg.setFont(QFont("Times New Roman", 14)) x = msg.exec_()