邮件通知功能上线
This commit is contained in:
122
AUTO_MAA.py
122
AUTO_MAA.py
@@ -63,6 +63,10 @@ import random
|
||||
import secrets
|
||||
import winreg
|
||||
import requests
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from email.header import Header
|
||||
from email.utils import formataddr
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.PublicKey import RSA
|
||||
from Crypto.Cipher import PKCS1_OAEP
|
||||
@@ -77,6 +81,7 @@ class MaaRunner(QtCore.QThread):
|
||||
|
||||
question = QtCore.Signal()
|
||||
push_notification = QtCore.Signal(str, str, str, int)
|
||||
send_mail = QtCore.Signal(str, str)
|
||||
update_gui = QtCore.Signal(str, str, str, str, str)
|
||||
update_user_info = QtCore.Signal(list, list, list, list, list, list)
|
||||
accomplish = QtCore.Signal()
|
||||
@@ -85,19 +90,18 @@ class MaaRunner(QtCore.QThread):
|
||||
"\\", "/"
|
||||
) # 获取软件自身的路径
|
||||
|
||||
def __init__(
|
||||
self, set_path, log_path, maa_path, routine, annihilation, num, data, mode
|
||||
):
|
||||
def __init__(self):
|
||||
super(MaaRunner, self).__init__()
|
||||
self.set_path = set_path
|
||||
self.log_path = log_path
|
||||
self.maa_path = maa_path
|
||||
self.set_path = None
|
||||
self.log_path = None
|
||||
self.maa_path = None
|
||||
self.json_path = f"{self.app_path}/data/MAAconfig"
|
||||
self.routine = routine
|
||||
self.annihilation = annihilation
|
||||
self.num = num
|
||||
self.data = data
|
||||
self.mode = mode
|
||||
self.routine = None
|
||||
self.annihilation = None
|
||||
self.num = None
|
||||
self.data = None
|
||||
self.if_send_mail = None
|
||||
self.mode = None
|
||||
self.get_json_path = [0, 0, 0]
|
||||
|
||||
def run(self):
|
||||
@@ -506,6 +510,11 @@ class MaaRunner(QtCore.QThread):
|
||||
f"已完成用户数:{len(over_index)},未完成用户数:{len(error_index) + len(wait_index)}",
|
||||
10,
|
||||
)
|
||||
if self.if_send_mail:
|
||||
self.send_mail.emit(
|
||||
f"{self.mode[:4]}任务报告",
|
||||
f"{end_log}\n\nAUTO_MAA 敬上\n\n我们根据您在 AUTO_MAA 中的设置发送了这封电子邮件,本邮件无需回复\n",
|
||||
)
|
||||
|
||||
self.accomplish.emit()
|
||||
|
||||
@@ -1240,6 +1249,12 @@ class Main(QWidget):
|
||||
)
|
||||
self.if_proxy_directly.stateChanged.connect(self.change_config)
|
||||
|
||||
self.if_send_mail = self.ui.findChild(QCheckBox, "checkBox_ifsendmail")
|
||||
self.if_send_mail.stateChanged.connect(self.change_config)
|
||||
|
||||
self.mail_address = self.ui.findChild(QLineEdit, "lineEdit_mailaddress")
|
||||
self.mail_address.textChanged.connect(self.change_config)
|
||||
|
||||
self.check_update = self.ui.findChild(QPushButton, "pushButton_check_update")
|
||||
self.check_update.clicked.connect(self.check_version)
|
||||
|
||||
@@ -1267,30 +1282,12 @@ class Main(QWidget):
|
||||
self.change_password.clicked.connect(self.change_PASSWORD)
|
||||
|
||||
# 初始化线程
|
||||
self.set_path_ = f"{self.config["Default"]["MaaSet.path"]}/config/gui.json"
|
||||
self.log_path_ = f"{self.config["Default"]["MaaSet.path"]}/debug/gui.log"
|
||||
self.maa_path_ = f"{self.config["Default"]["MaaSet.path"]}/MAA.exe"
|
||||
self.routine_ = self.config["Default"]["TimeLimit.routine"]
|
||||
self.annihilation_ = self.config["Default"]["TimeLimit.annihilation"]
|
||||
self.num_ = self.config["Default"]["TimesLimit.run"]
|
||||
self.cur.execute("SELECT * FROM adminx WHERE True")
|
||||
self.data_ = self.cur.fetchall()
|
||||
self.data_ = [list(row) for row in self.data_]
|
||||
|
||||
self.MaaRunner = MaaRunner(
|
||||
self.set_path_,
|
||||
self.log_path_,
|
||||
self.maa_path_,
|
||||
self.routine_,
|
||||
self.annihilation_,
|
||||
self.num_,
|
||||
self.data_,
|
||||
"未知",
|
||||
)
|
||||
self.MaaRunner = MaaRunner()
|
||||
self.MaaRunner.question.connect(lambda: self.read("question_runner"))
|
||||
self.MaaRunner.update_gui.connect(self.update_board)
|
||||
self.MaaRunner.update_user_info.connect(self.change_user_info)
|
||||
self.MaaRunner.push_notification.connect(self.push_notification)
|
||||
self.MaaRunner.send_mail.connect(self.send_mail)
|
||||
self.MaaRunner.accomplish.connect(lambda: self.maa_ender("日常代理_结束"))
|
||||
self.MaaRunner.get_json.connect(self.get_maa_config)
|
||||
|
||||
@@ -1392,6 +1389,8 @@ class Main(QWidget):
|
||||
["SelfSet.IfSelfStart", "False"],
|
||||
["SelfSet.IfSleep", "False"],
|
||||
["SelfSet.IfProxyDirectly", "False"],
|
||||
["SelfSet.IfSendMail", "False"],
|
||||
["SelfSet.MailAddress", ""],
|
||||
["SelfSet.UIsize", "1200x700"],
|
||||
["SelfSet.UIlocation", "100x100"],
|
||||
]
|
||||
@@ -1836,6 +1835,7 @@ class Main(QWidget):
|
||||
self.routine.setValue(self.config["Default"]["TimeLimit.routine"])
|
||||
self.annihilation.setValue(self.config["Default"]["TimeLimit.annihilation"])
|
||||
self.num.setValue(self.config["Default"]["TimesLimit.run"])
|
||||
self.mail_address.setText(self.config["Default"]["SelfSet.MailAddress"])
|
||||
|
||||
self.if_self_start.setChecked(
|
||||
bool(self.config["Default"]["SelfSet.IfSelfStart"] == "True")
|
||||
@@ -1849,6 +1849,14 @@ class Main(QWidget):
|
||||
bool(self.config["Default"]["SelfSet.IfProxyDirectly"] == "True")
|
||||
)
|
||||
|
||||
self.if_send_mail.setChecked(
|
||||
bool(self.config["Default"]["SelfSet.IfSendMail"] == "True")
|
||||
)
|
||||
|
||||
self.mail_address.setVisible(
|
||||
bool(self.config["Default"]["SelfSet.IfSendMail"] == "True")
|
||||
)
|
||||
|
||||
for i in range(10):
|
||||
self.start_time[i][0].setChecked(
|
||||
bool(self.config["Default"][f"TimeSet.set{i + 1}"] == "True")
|
||||
@@ -2270,6 +2278,7 @@ class Main(QWidget):
|
||||
self.config["Default"]["TimeLimit.routine"] = self.routine.value()
|
||||
self.config["Default"]["TimeLimit.annihilation"] = self.annihilation.value()
|
||||
self.config["Default"]["TimesLimit.run"] = self.num.value()
|
||||
self.config["Default"]["SelfSet.MailAddress"] = self.mail_address.text()
|
||||
|
||||
if self.if_sleep.isChecked():
|
||||
self.config["Default"]["SelfSet.IfSleep"] = "True"
|
||||
@@ -2286,6 +2295,11 @@ class Main(QWidget):
|
||||
else:
|
||||
self.config["Default"]["SelfSet.IfProxyDirectly"] = "False"
|
||||
|
||||
if self.if_send_mail.isChecked():
|
||||
self.config["Default"]["SelfSet.IfSendMail"] = "True"
|
||||
else:
|
||||
self.config["Default"]["SelfSet.IfSendMail"] = "False"
|
||||
|
||||
for i in range(10):
|
||||
if self.start_time[i][0].isChecked():
|
||||
self.config["Default"][f"TimeSet.set{i + 1}"] = "True"
|
||||
@@ -2390,10 +2404,19 @@ class Main(QWidget):
|
||||
self.MaaRunner.log_path = (
|
||||
f"{self.config["Default"]["MaaSet.path"]}/debug/gui.log"
|
||||
)
|
||||
self.MaaRunner.set_path = (
|
||||
f"{self.config["Default"]["MaaSet.path"]}/config/gui.json"
|
||||
)
|
||||
self.MaaRunner.log_path = (
|
||||
f"{self.config["Default"]["MaaSet.path"]}/debug/gui.log"
|
||||
)
|
||||
self.MaaRunner.maa_path = f"{self.config["Default"]["MaaSet.path"]}/MAA.exe"
|
||||
self.MaaRunner.routine = self.config["Default"]["TimeLimit.routine"]
|
||||
self.MaaRunner.annihilation = self.config["Default"]["TimeLimit.annihilation"]
|
||||
self.MaaRunner.num = self.config["Default"]["TimesLimit.run"]
|
||||
self.MaaRunner.if_send_mail = bool(
|
||||
self.config["Default"]["SelfSet.IfSendMail"] == "True"
|
||||
)
|
||||
self.cur.execute("SELECT * FROM adminx WHERE True")
|
||||
self.data_ = self.cur.fetchall()
|
||||
self.MaaRunner.data = [list(row) for row in self.data_]
|
||||
@@ -2421,6 +2444,9 @@ class Main(QWidget):
|
||||
f"{self.config["Default"]["MaaSet.path"]}/debug/gui.log"
|
||||
)
|
||||
self.MaaRunner.maa_path = f"{self.config["Default"]["MaaSet.path"]}/MAA.exe"
|
||||
self.MaaRunner.if_send_mail = bool(
|
||||
self.config["Default"]["SelfSet.IfSendMail"] == "True"
|
||||
)
|
||||
self.cur.execute("SELECT * FROM adminx WHERE True")
|
||||
self.data_ = self.cur.fetchall()
|
||||
self.MaaRunner.data = [list(row) for row in self.data_]
|
||||
@@ -2637,6 +2663,40 @@ class Main(QWidget):
|
||||
toast=True,
|
||||
)
|
||||
|
||||
def send_mail(self, title, content):
|
||||
"""使用官方专用邮箱推送邮件通知"""
|
||||
|
||||
# 第三方 SMTP 服务配置
|
||||
mail_host = "smtp.163.com" # 设置服务器
|
||||
mail_sender = "AUTO_MAA_server@163.com" # 用户名
|
||||
mail_key = "SYrq87nDLD4RNB5T" # 授权码 24/11/15
|
||||
|
||||
# 定义邮件正文
|
||||
message = MIMEText(content, "plain", "utf-8")
|
||||
message["From"] = formataddr(
|
||||
(Header("AUTO_MAA通知服务", "utf-8").encode(), "AUTO_MAA_server@163.com")
|
||||
) # 发件人显示的名字
|
||||
message["To"] = formataddr(
|
||||
(
|
||||
Header("AUTO_MAA用户", "utf-8").encode(),
|
||||
self.config["Default"]["SelfSet.MailAddress"],
|
||||
)
|
||||
) # 收件人显示的名字
|
||||
message["Subject"] = Header(title, "utf-8")
|
||||
|
||||
try:
|
||||
smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 465为SMTP_SSL默认端口
|
||||
smtpObj.login(mail_sender, mail_key)
|
||||
smtpObj.sendmail(
|
||||
mail_sender,
|
||||
self.config["Default"]["SelfSet.MailAddress"],
|
||||
message.as_string(),
|
||||
)
|
||||
except smtplib.SMTPException as e:
|
||||
QMessageBox.critical(self.ui, "错误", f"发送邮件时出错:\n{e}")
|
||||
finally:
|
||||
smtpObj.quit()
|
||||
|
||||
def give_config(self):
|
||||
"""同步配置文件到子线程"""
|
||||
|
||||
|
||||
135
gui/ui/main.ui
135
gui/ui/main.ui
@@ -189,8 +189,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>98</width>
|
||||
<height>74</height>
|
||||
<width>1156</width>
|
||||
<height>546</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@@ -1037,7 +1037,20 @@
|
||||
<property name="title">
|
||||
<string>AUTO_MAA设置</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4" columnstretch="1,1,1,1">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="2" column="1">
|
||||
<spacer name="horizontalSpacer_11">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>231</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frame_routine_3">
|
||||
<property name="frameShape">
|
||||
@@ -1070,18 +1083,37 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
<item row="2" column="0">
|
||||
<widget class="QFrame" name="frame_routine_4">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_20">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_ifproxydirectly">
|
||||
<property name="text">
|
||||
<string>启动AUTO_MAA后直接代理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_15">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QFrame" name="frame_routine_2">
|
||||
@@ -1128,52 +1160,20 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QFrame" name="frame_routine_4">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_20">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_ifproxydirectly">
|
||||
<property name="text">
|
||||
<string>启动AUTO_MAA后直接代理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_15">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<spacer name="horizontalSpacer_11">
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>231</width>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<item row="3" column="0">
|
||||
<widget class="QFrame" name="frame_check_update">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
@@ -1218,7 +1218,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<item row="3" column="1">
|
||||
<spacer name="horizontalSpacer_12">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
@@ -1231,6 +1231,41 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="2" colspan="2">
|
||||
<widget class="QFrame" name="frame_routine_5">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_22" stretch="0,1,3">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_ifsendmail">
|
||||
<property name="text">
|
||||
<string>通过邮件通知结果</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_16">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_mailaddress"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"main_version": "4.1.2.1",
|
||||
"main_version": "4.1.2.3",
|
||||
"main_download_url": "https://ghp.ci/https://github.com/DLmaster361/AUTO_MAA/releases/download/v4.1.2_beta/AUTO_MAA_v4.1.2_beta.zip",
|
||||
"updater_version": "1.0.4.0",
|
||||
"updater_download_url": "https://ghp.ci/https://github.com/DLmaster361/AUTO_MAA/releases/download/v4.1.2_beta/Updater_v1.0.4.zip",
|
||||
"announcement": "\n## 新增功能\n- 记忆窗口位置\n## 修复BUG\n- 暂无\n## 程序优化\n- 暂无"
|
||||
"announcement": "\n## 新增功能\n- 记忆窗口位置\n- 邮件通知功能上线\n## 修复BUG\n- 暂无\n## 程序优化\n- 优化`MaaRunner`初始化流程"
|
||||
}
|
||||
Reference in New Issue
Block a user