对于我的应用程序,我添加了“报告用户”功能。为了避免更长的代码,我打算将功能报告为另一个脚本。我想做的是,当一个用户报告另一个用户时,它将向我发送一封电子邮件。但是,当我运行下面的第一个脚本时,它只会向我发送一封空电子邮件,而不是我在UI面板上输入的数据。
主脚本
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import reportit
report_frame = QFrame()
report_frame.setWindowTitle('Report User')
report_box = QFormLayout(report_frame)
rp = QLabel("Enter the user you want to report:",report_frame)
reported_user = QLineEdit(report_frame)
cop = QLabel("Cause of report:",report_frame)
cause_of_report = QTextEdit(report_frame)
report_button_2 = QPushButton("Report the user")
def report():
target_user = reported_user.text()
cause = cause_of_report.toPlainText()
report_text_body = target_user,":", cause
reportit.send_report(report_text_body)
reportit.py
import smtplib
def send_report(msg):
from_addr = "suleymanyamantr@gmail.com"
to_addr= "suleymanyamantr@gmail.com"
username = "suleymanyamantr@gmail.com"
password = "XXXXX"
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(username, password)
server.sendmail(from_addr, to_addr, str(msg))
server.quit()