From 16ee6bf9c02b5f438455beb030011a978604f247 Mon Sep 17 00:00:00 2001 From: zq99299 <99299684@qq.com> Date: Mon, 22 Jul 2024 09:58:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E4=BD=BF=E7=94=A8=20text=20=E6=94=B9=E4=B8=BA=20html?= =?UTF-8?q?=20=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++++++- pyproject.toml | 2 +- src/tools_mrcode/mail_util.py | 6 +++--- .../{test_json_utils.py => test_json_util.py} | 0 tests/test_mail_util.py | 20 +++++++++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) rename tests/{test_json_utils.py => test_json_util.py} (100%) create mode 100644 tests/test_mail_util.py diff --git a/README.md b/README.md index 229eb1b..a4a587b 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,10 @@ ``` pip install tools-mrcode -``` \ No newline at end of file +``` + +## 更新日志 + +### v0.0.5 + +- 优化:mail_util.send 方法默认由 text 改为 html diff --git a/pyproject.toml b/pyproject.toml index 1fdef6a..661ed07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "tools_mrcode" -version = "0.0.4" +version = "0.0.5" authors = [ { name="mrcode", email="99299684@qq.com" }, ] diff --git a/src/tools_mrcode/mail_util.py b/src/tools_mrcode/mail_util.py index d6857bf..6b712b6 100644 --- a/src/tools_mrcode/mail_util.py +++ b/src/tools_mrcode/mail_util.py @@ -19,10 +19,10 @@ def send(smtp_host: str, smtp_port: int, smtp_user: str, smtp_pwd: str, sender: smtp.starttls() # 使用 TLS 加密 (如果使用 465 端口则不需要此行) smtp.login(smtp_user, smtp_pwd) - # 创建 MIMEText 对象 - msg = MIMEText(body) + # 创建 MIMEText 对象, 指定为 html 发送 + msg = MIMEText(body, 'html') + # msg = MIMEText(body) msg['Subject'] = subject msg['From'] = sender msg['To'] = to smtp.send_message(msg) - diff --git a/tests/test_json_utils.py b/tests/test_json_util.py similarity index 100% rename from tests/test_json_utils.py rename to tests/test_json_util.py diff --git a/tests/test_mail_util.py b/tests/test_mail_util.py new file mode 100644 index 0000000..7e61f2b --- /dev/null +++ b/tests/test_mail_util.py @@ -0,0 +1,20 @@ +import unittest +from src.tools_mrcode import mail_util + + +class MailUtilTestCase(unittest.TestCase): + def test_send(self): + smtp_host: str = 'smtp.163.com' + smtp_port: int = 25 + smtp_user: str = 'work_mrcode@163.com' + smtp_pwd: str = 'NLILRISEMYIUVXPH' + sender: str = smtp_user + to: str = '99299684@qq.com' + subject: str = '测试邮件' + body: str = '

测试邮件内容

测试邮件内容

' + body = (f'店铺 22
' + f'达人获取页面可能触发了风控,请手动访问该页面,检测并解控
' + f'当次推送成功达人数量 2 分钟 ') + mail_util.send(smtp_host=smtp_host, smtp_port=smtp_port, smtp_user=smtp_user, smtp_pwd=smtp_pwd, sender=sender, + to=to, + subject=subject, body=body)