simtoolsz 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simtoolsz-0.1.0/.gitignore +10 -0
- simtoolsz-0.1.0/.python-version +1 -0
- simtoolsz-0.1.0/LICENSE +134 -0
- simtoolsz-0.1.0/PKG-INFO +21 -0
- simtoolsz-0.1.0/README.md +11 -0
- simtoolsz-0.1.0/README_EN.md +9 -0
- simtoolsz-0.1.0/docs/mail_usage_guide.md +284 -0
- simtoolsz-0.1.0/examples/mail_examples.py +224 -0
- simtoolsz-0.1.0/pyproject.toml +26 -0
- simtoolsz-0.1.0/requirements-dev.lock +12 -0
- simtoolsz-0.1.0/requirements.lock +12 -0
- simtoolsz-0.1.0/src/simtoolsz/__init__.py +12 -0
- simtoolsz-0.1.0/src/simtoolsz/mail.py +617 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12.4
|
simtoolsz-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
木兰宽松许可证, 第2版
|
|
2
|
+
|
|
3
|
+
木兰宽松许可证, 第2版
|
|
4
|
+
|
|
5
|
+
2020年1月 http://license.coscl.org.cn/MulanPSL2
|
|
6
|
+
|
|
7
|
+
您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
|
|
8
|
+
|
|
9
|
+
0. 定义
|
|
10
|
+
|
|
11
|
+
“软件” 是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
|
|
12
|
+
|
|
13
|
+
“贡献” 是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
|
|
14
|
+
|
|
15
|
+
“贡献者” 是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
|
|
16
|
+
|
|
17
|
+
“法人实体” 是指提交贡献的机构及其“关联实体”。
|
|
18
|
+
|
|
19
|
+
“关联实体” 是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
|
|
20
|
+
|
|
21
|
+
1. 授予版权许可
|
|
22
|
+
|
|
23
|
+
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
|
|
24
|
+
|
|
25
|
+
2. 授予专利许可
|
|
26
|
+
|
|
27
|
+
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
|
|
28
|
+
|
|
29
|
+
3. 无商标许可
|
|
30
|
+
|
|
31
|
+
“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
|
|
32
|
+
|
|
33
|
+
4. 分发限制
|
|
34
|
+
|
|
35
|
+
您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
|
|
36
|
+
|
|
37
|
+
5. 免责声明与责任限制
|
|
38
|
+
|
|
39
|
+
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
|
|
40
|
+
|
|
41
|
+
6. 语言
|
|
42
|
+
|
|
43
|
+
“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
|
|
44
|
+
|
|
45
|
+
条款结束
|
|
46
|
+
|
|
47
|
+
如何将木兰宽松许可证,第2版,应用到您的软件
|
|
48
|
+
|
|
49
|
+
如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
|
|
50
|
+
|
|
51
|
+
1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
|
|
52
|
+
|
|
53
|
+
2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
|
|
54
|
+
|
|
55
|
+
3, 请将如下声明文本放入每个源文件的头部注释中。
|
|
56
|
+
|
|
57
|
+
Copyright (c) 2025 Sidney Zhang
|
|
58
|
+
simtoolsz is licensed under Mulan PSL v2.
|
|
59
|
+
|
|
60
|
+
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
61
|
+
You may obtain a copy of Mulan PSL v2 at:
|
|
62
|
+
http://license.coscl.org.cn/MulanPSL2
|
|
63
|
+
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
64
|
+
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
65
|
+
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
66
|
+
See the Mulan PSL v2 for more details.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Mulan Permissive Software License,Version 2
|
|
70
|
+
|
|
71
|
+
Mulan Permissive Software License,Version 2 (Mulan PSL v2)
|
|
72
|
+
|
|
73
|
+
January 2020 http://license.coscl.org.cn/MulanPSL2
|
|
74
|
+
|
|
75
|
+
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
|
|
76
|
+
|
|
77
|
+
0. Definition
|
|
78
|
+
|
|
79
|
+
Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
|
|
80
|
+
|
|
81
|
+
Contribution means the copyrightable work licensed by a particular Contributor under this License.
|
|
82
|
+
|
|
83
|
+
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
|
|
84
|
+
|
|
85
|
+
Legal Entity means the entity making a Contribution and all its Affiliates.
|
|
86
|
+
|
|
87
|
+
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
|
|
88
|
+
|
|
89
|
+
1. Grant of Copyright License
|
|
90
|
+
|
|
91
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
|
|
92
|
+
|
|
93
|
+
2. Grant of Patent License
|
|
94
|
+
|
|
95
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
|
|
96
|
+
|
|
97
|
+
3. No Trademark License
|
|
98
|
+
|
|
99
|
+
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4.
|
|
100
|
+
|
|
101
|
+
4. Distribution Restriction
|
|
102
|
+
|
|
103
|
+
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
|
|
104
|
+
|
|
105
|
+
5. Disclaimer of Warranty and Limitation of Liability
|
|
106
|
+
|
|
107
|
+
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
108
|
+
|
|
109
|
+
6. Language
|
|
110
|
+
|
|
111
|
+
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
|
|
112
|
+
|
|
113
|
+
END OF THE TERMS AND CONDITIONS
|
|
114
|
+
|
|
115
|
+
How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
|
|
116
|
+
|
|
117
|
+
To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
|
|
118
|
+
|
|
119
|
+
Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
|
|
120
|
+
|
|
121
|
+
Create a file named "LICENSE" which contains the whole context of this License in the first directory of your software package;
|
|
122
|
+
|
|
123
|
+
Attach the statement to the appropriate annotated syntax at the beginning of each source file.
|
|
124
|
+
|
|
125
|
+
Copyright (c) 2025 Sidney Zhang
|
|
126
|
+
simtoolsz is licensed under Mulan PSL v2.
|
|
127
|
+
|
|
128
|
+
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
129
|
+
You may obtain a copy of Mulan PSL v2 at:
|
|
130
|
+
http://license.coscl.org.cn/MulanPSL2
|
|
131
|
+
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
132
|
+
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
133
|
+
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
134
|
+
See the Mulan PSL v2 for more details.
|
simtoolsz-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: simtoolsz
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple tool collection.
|
|
5
|
+
Author-email: Sidney Zhang <liangyi@me.com>
|
|
6
|
+
License: MulanPSL-2.0
|
|
7
|
+
Keywords: collection,tool
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# simtoolsz
|
|
12
|
+
|
|
13
|
+
[English](README_EN.md) | 中文
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
一个简单、方便的工具集合,包含一些好用的函数、类、方法。
|
|
17
|
+
|
|
18
|
+
计划把我之前写的[工具包](https://github.com/SidneyLYZhang/pytoolsz)做一些精简,之前的包被我塞了太多的东西。
|
|
19
|
+
现在做一些精简,保留最常用的哪些工具,以及一些常用的函数。
|
|
20
|
+
|
|
21
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# simtoolsz
|
|
2
|
+
|
|
3
|
+
English | [中文](README.md)
|
|
4
|
+
|
|
5
|
+
A simple and convenient toolkit containing useful functions, classes, and methods.
|
|
6
|
+
|
|
7
|
+
Planning to streamline my previously written [toolkit](https://github.com/SidneyLYZhang/pytoolsz),
|
|
8
|
+
as the previous package had accumulated too many things.
|
|
9
|
+
Now doing some simplification, keeping only the most commonly used tools and some frequently used functions.
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# 邮件功能使用指南
|
|
2
|
+
|
|
3
|
+
本指南介绍如何使用优化后的邮件发送和接收功能。
|
|
4
|
+
|
|
5
|
+
## 📧 发送邮件 - send_email
|
|
6
|
+
|
|
7
|
+
### 基本功能
|
|
8
|
+
- 发送纯文本或HTML格式邮件
|
|
9
|
+
- 支持多个收件人、抄送、密送
|
|
10
|
+
- 支持附件和内嵌图片
|
|
11
|
+
- 自动识别主流邮箱SMTP配置
|
|
12
|
+
- 详细的错误处理和返回信息
|
|
13
|
+
|
|
14
|
+
### 参数说明
|
|
15
|
+
|
|
16
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
17
|
+
|---|---|---|---|
|
|
18
|
+
| email_account | str | ✅ | 邮箱账号(如:user@qq.com) |
|
|
19
|
+
| password | str | ✅ | 邮箱密码或授权码 |
|
|
20
|
+
| subject | str | ✅ | 邮件主题 |
|
|
21
|
+
| content | str | ✅ | 邮件正文内容 |
|
|
22
|
+
| recipients | str/list | ✅ | 收件人邮箱(支持单个邮箱字符串或多个邮箱列表) |
|
|
23
|
+
| attachments | list | ❌ | 附件文件路径列表 |
|
|
24
|
+
| cc_recipients | list | ❌ | 抄送邮箱列表 |
|
|
25
|
+
| bcc_recipients | list | ❌ | 密送邮箱列表 |
|
|
26
|
+
| sender_name | str | ❌ | 发件人显示名称 |
|
|
27
|
+
| html_mode | bool | ❌ | 是否使用HTML格式(默认False) |
|
|
28
|
+
| inline_images | dict | ❌ | 内嵌图片({cid: filepath}格式) |
|
|
29
|
+
| signature | str | ❌ | 邮件签名 |
|
|
30
|
+
| smtp_config | dict | ❌ | 自定义SMTP配置 |
|
|
31
|
+
| timeout | int | ❌ | 超时时间(秒,默认30) |
|
|
32
|
+
|
|
33
|
+
### 返回值格式
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
{
|
|
37
|
+
"success": bool, # 是否成功
|
|
38
|
+
"message": str, # 状态信息
|
|
39
|
+
"recipient_count": int, # 成功发送的收件人数量
|
|
40
|
+
"failed_recipients": list # 发送失败的收件人列表
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 使用示例
|
|
45
|
+
|
|
46
|
+
#### 1. 发送简单文本邮件
|
|
47
|
+
```python
|
|
48
|
+
from simtoolsz.mail import send_email
|
|
49
|
+
|
|
50
|
+
result = send_email(
|
|
51
|
+
email_account="user@qq.com",
|
|
52
|
+
password="your_password",
|
|
53
|
+
subject="测试邮件",
|
|
54
|
+
content="这是一封测试邮件",
|
|
55
|
+
recipients="recipient@example.com"
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### 2. 发送带附件的邮件
|
|
60
|
+
```python
|
|
61
|
+
result = send_email(
|
|
62
|
+
email_account="user@163.com",
|
|
63
|
+
password="auth_code",
|
|
64
|
+
subject="工作报告",
|
|
65
|
+
content="请查收本周工作报告",
|
|
66
|
+
recipients=["boss@company.com", "colleague@company.com"],
|
|
67
|
+
attachments=["report.pdf", "data.xlsx"],
|
|
68
|
+
cc_recipients=["manager@company.com"]
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### 3. 发送HTML格式邮件
|
|
73
|
+
```python
|
|
74
|
+
result = send_email(
|
|
75
|
+
email_account="user@gmail.com",
|
|
76
|
+
password="app_password",
|
|
77
|
+
subject="产品通知",
|
|
78
|
+
content="""
|
|
79
|
+
<h1>新产品发布</h1>
|
|
80
|
+
<p>我们很高兴地通知您,新产品已上线!</p>
|
|
81
|
+
<img src="cid:product_image" style="width: 300px;">
|
|
82
|
+
""",
|
|
83
|
+
recipients="client@example.com",
|
|
84
|
+
html_mode=True,
|
|
85
|
+
inline_images={"product_image": "product.jpg"}
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### 4. 使用自定义SMTP配置
|
|
90
|
+
```python
|
|
91
|
+
result = send_email(
|
|
92
|
+
email_account="user@company.com",
|
|
93
|
+
password="password",
|
|
94
|
+
subject="系统通知",
|
|
95
|
+
content="系统维护通知",
|
|
96
|
+
recipients="all@company.com",
|
|
97
|
+
smtp_config={
|
|
98
|
+
"server": "smtp.company.com",
|
|
99
|
+
"port": 587,
|
|
100
|
+
"use_ssl": True
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## 📥 获取邮件 - fetch_emails
|
|
106
|
+
|
|
107
|
+
### 基本功能
|
|
108
|
+
- 按条件搜索和获取邮件
|
|
109
|
+
- 支持下载邮件附件
|
|
110
|
+
- 支持多种搜索模式(精确、模糊、正则)
|
|
111
|
+
- 自动识别主流邮箱IMAP配置
|
|
112
|
+
- 详细的邮件信息返回
|
|
113
|
+
|
|
114
|
+
### 参数说明
|
|
115
|
+
|
|
116
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
117
|
+
|---|---|---|---|
|
|
118
|
+
| email_account | str | ✅ | 邮箱账号 |
|
|
119
|
+
| password | str | ✅ | 邮箱密码或授权码 |
|
|
120
|
+
| subject | str | ❌ | 搜索主题关键词 |
|
|
121
|
+
| sender | str | ❌ | 发件人邮箱 |
|
|
122
|
+
| date_range | tuple | ❌ | 日期范围((start_date, end_date)) |
|
|
123
|
+
| search_mode | str | ❌ | 搜索模式:exact/fuzzy/regex |
|
|
124
|
+
| max_emails | int | ❌ | 最大获取邮件数量 |
|
|
125
|
+
| download_attachments | bool | ❌ | 是否下载附件 |
|
|
126
|
+
| attachment_dir | str | ❌ | 附件保存目录 |
|
|
127
|
+
| imap_config | dict | ❌ | 自定义IMAP配置 |
|
|
128
|
+
|
|
129
|
+
### 返回值格式
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
{
|
|
133
|
+
"success": bool, # 是否成功
|
|
134
|
+
"message": str, # 状态信息
|
|
135
|
+
"email_count": int, # 获取的邮件数量
|
|
136
|
+
"emails": [ # 邮件列表
|
|
137
|
+
{
|
|
138
|
+
"subject": str, # 主题
|
|
139
|
+
"from": str, # 发件人
|
|
140
|
+
"to": str, # 收件人
|
|
141
|
+
"date": str, # 日期
|
|
142
|
+
"text_body": str, # 纯文本内容
|
|
143
|
+
"html_body": str, # HTML内容
|
|
144
|
+
"size": int, # 邮件大小(字节)
|
|
145
|
+
"attachments": [ # 附件列表
|
|
146
|
+
{
|
|
147
|
+
"filename": str, # 文件名
|
|
148
|
+
"size": int, # 文件大小
|
|
149
|
+
"filepath": str # 保存路径
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
"attachments_dir": str # 附件保存目录
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 使用示例
|
|
159
|
+
|
|
160
|
+
#### 1. 获取最新邮件
|
|
161
|
+
```python
|
|
162
|
+
from simtoolsz.mail import fetch_emails
|
|
163
|
+
from datetime import datetime, timedelta
|
|
164
|
+
|
|
165
|
+
result = fetch_emails(
|
|
166
|
+
email_account="user@qq.com",
|
|
167
|
+
password="password",
|
|
168
|
+
max_emails=10
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
if result["success"]:
|
|
172
|
+
for email in result["emails"]:
|
|
173
|
+
print(f"主题: {email['subject']}")
|
|
174
|
+
print(f"发件人: {email['from']}")
|
|
175
|
+
print(f"日期: {email['date']}")
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### 2. 按主题搜索邮件
|
|
179
|
+
```python
|
|
180
|
+
result = fetch_emails(
|
|
181
|
+
email_account="user@163.com",
|
|
182
|
+
password="auth_code",
|
|
183
|
+
subject="工作报告",
|
|
184
|
+
search_mode="fuzzy",
|
|
185
|
+
date_range=(datetime.now() - timedelta(days=7), datetime.now())
|
|
186
|
+
)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### 3. 获取特定发件人的邮件
|
|
190
|
+
```python
|
|
191
|
+
result = fetch_emails(
|
|
192
|
+
email_account="user@gmail.com",
|
|
193
|
+
password="app_password",
|
|
194
|
+
sender="reports@company.com",
|
|
195
|
+
max_emails=5
|
|
196
|
+
)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### 4. 下载邮件附件
|
|
200
|
+
```python
|
|
201
|
+
result = fetch_emails(
|
|
202
|
+
email_account="user@company.com",
|
|
203
|
+
password="password",
|
|
204
|
+
subject="数据报告",
|
|
205
|
+
download_attachments=True,
|
|
206
|
+
attachment_dir="./downloads",
|
|
207
|
+
max_emails=3
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
if result["success"]:
|
|
211
|
+
for email in result["emails"]:
|
|
212
|
+
if email["attachments"]:
|
|
213
|
+
print(f"邮件 '{email['subject']}' 包含附件:")
|
|
214
|
+
for att in email["attachments"]:
|
|
215
|
+
print(f" - {att['filename']} -> {att['filepath']}")
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## 🔧 邮箱配置参考
|
|
219
|
+
|
|
220
|
+
### 常用邮箱SMTP/IMAP设置
|
|
221
|
+
|
|
222
|
+
| 邮箱服务商 | SMTP服务器 | SMTP端口 | IMAP服务器 | IMAP端口 | 备注 |
|
|
223
|
+
|---|---|---|---|---|---|
|
|
224
|
+
| QQ邮箱 | smtp.qq.com | 465/587 | imap.qq.com | 993 | 需使用授权码 |
|
|
225
|
+
| 163邮箱 | smtp.163.com | 465/994 | imap.163.com | 993 | 需使用授权码 |
|
|
226
|
+
| Gmail | smtp.gmail.com | 465/587 | imap.gmail.com | 993 | 需使用应用专用密码 |
|
|
227
|
+
| Outlook | smtp-mail.outlook.com | 587 | imap-mail.outlook.com | 993 | 需使用应用密码 |
|
|
228
|
+
| 126邮箱 | smtp.126.com | 465/994 | imap.126.com | 993 | 需使用授权码 |
|
|
229
|
+
|
|
230
|
+
### 获取授权码方法
|
|
231
|
+
|
|
232
|
+
#### QQ邮箱授权码
|
|
233
|
+
1. 登录QQ邮箱网页版
|
|
234
|
+
2. 进入 设置 > 账户
|
|
235
|
+
3. 找到 "POP3/SMTP服务" 并开启
|
|
236
|
+
4. 生成授权码
|
|
237
|
+
|
|
238
|
+
#### 163邮箱授权码
|
|
239
|
+
1. 登录163邮箱网页版
|
|
240
|
+
2. 进入 设置 > POP3/SMTP/IMAP
|
|
241
|
+
3. 开启SMTP/IMAP服务
|
|
242
|
+
4. 获取授权码
|
|
243
|
+
|
|
244
|
+
#### Gmail应用专用密码
|
|
245
|
+
1. 登录Google账户
|
|
246
|
+
2. 进入 安全性 > 两步验证
|
|
247
|
+
3. 找到 "应用专用密码"
|
|
248
|
+
4. 生成用于邮件的密码
|
|
249
|
+
|
|
250
|
+
## ⚠️ 注意事项
|
|
251
|
+
|
|
252
|
+
1. **安全性**
|
|
253
|
+
- 不要将密码硬编码在代码中
|
|
254
|
+
- 使用环境变量或配置文件存储敏感信息
|
|
255
|
+
- 定期更换授权码
|
|
256
|
+
|
|
257
|
+
2. **性能**
|
|
258
|
+
- 大量邮件获取时设置合理的max_emails值
|
|
259
|
+
- 大附件下载时注意磁盘空间
|
|
260
|
+
- 设置合适的timeout值避免网络超时
|
|
261
|
+
|
|
262
|
+
3. **错误处理**
|
|
263
|
+
- 始终检查返回值的success字段
|
|
264
|
+
- 查看message字段获取详细错误信息
|
|
265
|
+
- 网络异常时重试机制
|
|
266
|
+
|
|
267
|
+
4. **兼容性**
|
|
268
|
+
- 旧函数名quick_send_email和load_email_by_subject仍可使用
|
|
269
|
+
- 新函数提供更好的错误处理和返回值
|
|
270
|
+
|
|
271
|
+
## 🚀 快速开始
|
|
272
|
+
|
|
273
|
+
1. 安装依赖:确保已安装所需Python包
|
|
274
|
+
2. 获取授权码:根据邮箱类型获取相应的授权码
|
|
275
|
+
3. 运行示例:参考examples/mail_examples.py中的示例代码
|
|
276
|
+
4. 集成项目:将函数集成到你的项目中
|
|
277
|
+
|
|
278
|
+
## 📞 技术支持
|
|
279
|
+
|
|
280
|
+
如遇到问题,请检查:
|
|
281
|
+
- 网络连接是否正常
|
|
282
|
+
- 邮箱账号和密码是否正确
|
|
283
|
+
- 邮箱服务是否已开启SMTP/IMAP
|
|
284
|
+
- 防火墙是否阻止了相应端口
|