您好,我正在尝试从youtube视频中复制代码的副本,但是代码崩溃并且python停止了clickfunction的工作。
on_clickSendEmail,on_clickTestEmail和sendTestEmail基本不起作用python崩溃可以由任何人来帮助@ekhumoro
以下是引用代码:
import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication,QMainWindow
from PyQt5.uic import loadUi
import boto3
from botocore.exceptions import ClientError
class tutorial(QMainWindow):
def __init__(self):
super(tutorial, self).__init__()
loadUi('pelican.ui',self)
self.setWindowTitle('Test Environment')
self.subject.setPlainText('This is a Test email')
self.textEdit.setPlainText('Hi All')
self.totalemail.setText('9887')
self.totalavailableemail.setText('10000')
self.testemailsend.clicked.connect(self.on_clickTestEmail)
self.sendemail.clicked.connect(self.on_clickSendEmail)
@pyqtSlot()
def on_clickTestEmail(self):
print('User has pressed the Email test Push Button')
subject = self.subject.toPlainText()
message = self.textEdit.toPlainText()
fromEmail = self.fromemail.currentText()
toEmail = self.testemailedit.toPlainText()
sendTestEmail(fromEmail,subject,message,toEmail)
@pyqtSlot()
def on_clickSendEmail(self):
print('User has pressed the Email send Push Button')
sendEmailCheck = self.checkBox.isChecked()
if sendEmailCheck:
self.checkBoxAlert.clear()
print('Now You can send your emails')
else:
print('Please,First Check Your test email')
self.checkBoxAlert.setPlainText('Please,First Check Your test email')
def sendTestEmail(fromEmail,subject,message,toEmail):
print('From:',fromEmail)
print('To:',toEmail)
print('Subject:',subject)
print('Message:',message)
def send(fromEmail,subject,message,toEmail):
SENDER = fromEmail
# Replace recipient@example.com with a "To" address. If your account
# is still in the sandbox, this address must be verified.
RECIPIENT = toEmail
# Specify a configuration set. If you do not want to use a configuration
# set, comment the following variable, and the
# ConfigurationSetName=CONFIGURATION_SET argument below.
CONFIGURATION_SET = "pelican.ui"
# If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
# The subject line for the email.
SUBJECT = subject
# The email body for recipients with non-HTML email clients.
BODY_TEXT = message
# The HTML body of the email.
BODY_HTML = message
# The character encoding for the email.
CHARSET = "UTF-8"
# Create a new SES resource and specify a region.
client = boto3.client('ses')
# Try to send the email.
try:
# Provide the contents of the email.
response = client.send_email(
Destination={
'ToAddresses': [
RECIPIENT,
],
},
Message={
'Body': {
'Html': {
'Charset': CHARSET,
'Data': BODY_HTML,
},
'Text': {
'Charset': CHARSET,
'Data': BODY_TEXT,
},
},
'Subject': {
'Charset': CHARSET,
'Data': SUBJECT,
},
},
Source=SENDER,
# If you are not using a configuration set, comment or delete the
# following line
ConfigurationSetName=CONFIGURATION_SET,
)
# Display an error if something goes wrong.
except ClientError as e:
print(e.response['Error']['Message'])
else:
print("Email sent! Message ID:"),
print(response['MessageId'])
app = QApplication(sys.argv)
widget = tutorial()
widget.show()
sys.exit(app.exec_())