Skip to content

Commit

Permalink
[Mod] catch exception when sending email and write log, close #3580
Browse files Browse the repository at this point in the history
  • Loading branch information
vnpy committed Dec 26, 2024
1 parent 6c44aee commit 61d56da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
20 changes: 13 additions & 7 deletions vnpy/trader/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from logging import Logger
import smtplib
import os
import traceback
from abc import ABC
from pathlib import Path
from datetime import datetime
Expand Down Expand Up @@ -646,17 +647,22 @@ def send_email(self, subject: str, content: str, receiver: str = "") -> None:

def run(self) -> None:
""""""
server: str = SETTINGS["email.server"]
port: int = SETTINGS["email.port"]
username: str = SETTINGS["email.username"]
password: str = SETTINGS["email.password"]

while self.active:
try:
msg: EmailMessage = self.queue.get(block=True, timeout=1)

with smtplib.SMTP_SSL(
SETTINGS["email.server"], SETTINGS["email.port"]
) as smtp:
smtp.login(
SETTINGS["email.username"], SETTINGS["email.password"]
)
smtp.send_message(msg)
try:
with smtplib.SMTP_SSL(server, port) as smtp:
smtp.login(username, password)
smtp.send_message(msg)
except Exception:
msg: str = _("邮件发送失败: {}").format(traceback.format_exc())
self.main_engine.write_log(msg, "EMAIL")
except Empty:
pass

Expand Down
4 changes: 4 additions & 0 deletions vnpy/trader/locale/en/LC_MESSAGES/vnpy.po
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ msgstr "Gateway not found: {}"
msgid "找不到引擎:{}"
msgstr "Engine not found: {}"

#: vnpy\trader\engine.py:663
msgid "邮件发送失败: {}"
msgstr "Sending email failed: {}"

#: vnpy\trader\optimize.py:45
msgid "固定参数添加成功"
msgstr "Fixed parameter added successfully"
Expand Down
6 changes: 5 additions & 1 deletion vnpy/trader/locale/vnpy.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-03-21 16:21+0800\n"
"POT-Creation-Date: 2024-12-26 12:21+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -159,6 +159,10 @@ msgstr ""
msgid "找不到引擎:{}"
msgstr ""

#: vnpy\trader\engine.py:663
msgid "邮件发送失败: {}"
msgstr ""

#: vnpy\trader\optimize.py:45
msgid "固定参数添加成功"
msgstr ""
Expand Down

0 comments on commit 61d56da

Please sign in to comment.