This commit is contained in:
2025-01-14 17:16:12 +08:00
parent f3bcc71ced
commit 4c3d157234
2 changed files with 67 additions and 5 deletions
+4 -3
View File
@@ -10,12 +10,13 @@ from flask_cors import CORS
from src.My_Logger.project_logger import LoggerClass from src.My_Logger.project_logger import LoggerClass
from src.ark_helper_backend.backend import ArkHelperBackend from src.ark_helper_backend.backend import ArkHelperBackend
from src.util.mail import send_batch_email from src.util.mail import send_batch_email, new_send_email
from src.util.utils import random_time from src.util.utils import random_time
app = Flask(__name__) app = Flask(__name__)
CORS(app, supports_credentials=True) CORS(app, supports_credentials=True)
admin_key = '1145141919810' admin_key = '1145141919810'
target_email_list = ['ArmorServer@outlook.com']
@app.route("/GetCurrentStatus", methods=["POST"]) @app.route("/GetCurrentStatus", methods=["POST"])
@@ -102,7 +103,7 @@ def data_retrieve_thread():
except Exception as e: except Exception as e:
print(e, traceback.format_exc()) print(e, traceback.format_exc())
ark_back.logger.error(traceback.format_exc()) ark_back.logger.error(traceback.format_exc())
send_batch_email(['2654988228@qq.com'], 'Error in ArkHelper data retrieval', str(traceback.format_exc())) new_send_email(target_email_list, 'Error in ArkHelper data retrieval', str(traceback.format_exc()))
finally: finally:
ark_back.logger.info('Data Retrieve Stopped') ark_back.logger.info('Data Retrieve Stopped')
@@ -123,7 +124,7 @@ def skland_sign_in_thread():
except Exception as e: except Exception as e:
print(e, traceback.format_exc()) print(e, traceback.format_exc())
ark_back.logger.error(traceback.format_exc()) ark_back.logger.error(traceback.format_exc())
send_batch_email(['2654988228@qq.com'], 'Error in ArkHelper Skland Sign-in', str(traceback.format_exc())) new_send_email(target_email_list, 'Error in ArkHelper Skland Sign-in', str(traceback.format_exc()))
finally: finally:
ark_back.logger.info('Data Retrieve Stopped') ark_back.logger.info('Data Retrieve Stopped')
+63 -2
View File
@@ -1,4 +1,6 @@
import smtplib import smtplib
import traceback
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase from email.mime.base import MIMEBase
@@ -63,8 +65,67 @@ def send_batch_email(receiver_email_list, subject, content, file_path=None):
server.quit() server.quit()
def new_send_email(receiver_email_list, subject, content, file_path=None):
"""
Send Email to the receiver list. Can attach files if needed.
:param receiver_email_list:
:param subject: Title
:param content: Word Content
:param file_path: file list
:return:
"""
# sender config
sender_email = "2654988228@qq.com"
password = 'mdibrqwjqmdyeabe'
# mail content
message = MIMEMultipart()
message["Subject"] = subject
message["From"] = sender_email
# main body
part1 = MIMEText(content, "plain")
message.attach(part1)
if file_path and isinstance(file_path, list):
for filename in file_path:
# 指定附件的路径和文件名
attachment = open(filename, 'rb')
# 创建MIMEBase实例
part = MIMEBase('application', 'octet-stream')
part.set_payload(attachment.read())
encoders.encode_base64(part)
# 添加邮件头
part.add_header(
'Content-Disposition',
f'attachment; filename= {filename}',
)
message.attach(part)
attachment.close()
# 登录SMTP服务器并发送邮件
# 使用Hotmail的SMTP服务器
server = smtplib.SMTP('smtp.qq.com', 587)
try:
server.starttls() # 启用安全传输模式
server.login(sender_email, password)
for receiver_email in receiver_email_list:
message["To"] = receiver_email
server.sendmail(sender_email, receiver_email, message.as_string())
print(f"Email to {receiver_email} sent successfully!")
except Exception as e:
print(f"Error: {e}")
print(str(traceback.format_exc()))
finally:
server.quit()
if __name__ == '__main__': if __name__ == '__main__':
target_email_list = ['2654988228@qq.com'] # target_email_list = ['2654988228@qq.com']
target_email_list = ['ArmorServer@outlook.com', '2654988228@qq.com']
email_subject = 'Test Message' email_subject = 'Test Message'
email_body = """ email_body = """
This is a test email This is a test email
@@ -72,5 +133,5 @@ if __name__ == '__main__':
email_file_list = [] email_file_list = []
send_batch_email(target_email_list, email_subject, email_body, email_file_list) new_send_email(target_email_list, email_subject, email_body, email_file_list)