Skip to content

Commit

Permalink
Merge pull request #4 from zq99299/dev
Browse files Browse the repository at this point in the history
邮件发送默认使用 text 改为 html 发送
  • Loading branch information
zq99299 authored Jul 22, 2024
2 parents 94d8a07 + 16ee6bf commit 82e2602
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@

```
pip install tools-mrcode
```
```

## 更新日志

### v0.0.5

- 优化:mail_util.send 方法默认由 text 改为 html
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
]
Expand Down
6 changes: 3 additions & 3 deletions src/tools_mrcode/mail_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

File renamed without changes.
20 changes: 20 additions & 0 deletions tests/test_mail_util.py
Original file line number Diff line number Diff line change
@@ -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 = '<p>测试邮件内容</p><h1>测试邮件内容</h1>'
body = (f'店铺 22 </br> '
f'达人获取页面可能触发了风控,请手动访问该页面,检测并解控 </br> '
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)

0 comments on commit 82e2602

Please sign in to comment.