UtilityLibAPI 1.2511.282__tar.gz → 1.2511.292__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.
- {utilitylibapi-1.2511.282/src/UtilityLibAPI.egg-info → utilitylibapi-1.2511.292}/PKG-INFO +8 -1
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/README.md +7 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/pyproject.toml +1 -1
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI/MailSenderLib.py +54 -22
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292/src/UtilityLibAPI.egg-info}/PKG-INFO +8 -1
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/LICENSE +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/setup.cfg +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI/Archive7zLib.py +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI/EnDeCodeLib.py +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI/ExtWrapper7zLib.py +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI/SessionVARLib.py +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI/__init__.py +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI.egg-info/SOURCES.txt +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI.egg-info/dependency_links.txt +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI.egg-info/requires.txt +0 -0
- {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: UtilityLibAPI
|
|
3
|
-
Version: 1.2511.
|
|
3
|
+
Version: 1.2511.292
|
|
4
4
|
Summary: UtilityLibAPI Python package
|
|
5
5
|
Author-email: James Lin <tylin123@ms27.hinet.net>
|
|
6
6
|
License: Copyright (c) 2025 James Lin **UtilityLibAPI**
|
|
@@ -33,6 +33,13 @@ Dynamic: license-file
|
|
|
33
33
|
#UtilityLibAPI Classes
|
|
34
34
|
|
|
35
35
|
## History of version
|
|
36
|
+
Version 1.2511.292: 2025/11/29<BR>
|
|
37
|
+
Add Event for send mail when success or failure.
|
|
38
|
+
|
|
39
|
+
Version 1.2511.291: 2025/11/29<BR>
|
|
40
|
+
Fixed MailSenderLib: Attachement file name encode problem.
|
|
41
|
+
Add function for user can modify mail caption of from field.
|
|
42
|
+
|
|
36
43
|
Version 1.2511.282: 2025/11/27<BR>
|
|
37
44
|
Fixed MailSenderLib: Attachement file name encode problem.
|
|
38
45
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
#UtilityLibAPI Classes
|
|
2
2
|
|
|
3
3
|
## History of version
|
|
4
|
+
Version 1.2511.292: 2025/11/29<BR>
|
|
5
|
+
Add Event for send mail when success or failure.
|
|
6
|
+
|
|
7
|
+
Version 1.2511.291: 2025/11/29<BR>
|
|
8
|
+
Fixed MailSenderLib: Attachement file name encode problem.
|
|
9
|
+
Add function for user can modify mail caption of from field.
|
|
10
|
+
|
|
4
11
|
Version 1.2511.282: 2025/11/27<BR>
|
|
5
12
|
Fixed MailSenderLib: Attachement file name encode problem.
|
|
6
13
|
|
|
@@ -2,8 +2,10 @@ import smtplib
|
|
|
2
2
|
from email.mime.text import MIMEText
|
|
3
3
|
from email.mime.multipart import MIMEMultipart
|
|
4
4
|
from email.mime.application import MIMEApplication
|
|
5
|
+
from email.mime.base import MIMEBase
|
|
5
6
|
from email.utils import formataddr
|
|
6
7
|
from email.header import Header
|
|
8
|
+
from email import encoders
|
|
7
9
|
from typing import List, Optional
|
|
8
10
|
import os
|
|
9
11
|
import mimetypes
|
|
@@ -24,10 +26,16 @@ class CLASS_MailSender:
|
|
|
24
26
|
:param Pmb_UseSSL: 是否使用 SSL 連線 (預設 True)
|
|
25
27
|
"""
|
|
26
28
|
self.Pms_SMTP_Server = Pms_SMTP_Server
|
|
27
|
-
self.Pmi_Port
|
|
28
|
-
self.Pms_Account
|
|
29
|
-
self.Pms_Password
|
|
30
|
-
self.Pmb_UseSSL
|
|
29
|
+
self.Pmi_Port = Pmi_Port
|
|
30
|
+
self.Pms_Account = Pms_Account
|
|
31
|
+
self.Pms_Password = Pms_Password
|
|
32
|
+
self.Pmb_UseSSL = Pmb_UseSSL
|
|
33
|
+
# ======================================================================
|
|
34
|
+
# 新增事件
|
|
35
|
+
# ======================================================================
|
|
36
|
+
self.OnAfterSendSuccess: Optional[Callable[[str], None]] = None
|
|
37
|
+
self.OnAfterSendFailure: Optional[Callable[[str], None]] = None
|
|
38
|
+
|
|
31
39
|
|
|
32
40
|
#------------------------------------------------------------
|
|
33
41
|
def CUF_CreateMessage(self,
|
|
@@ -40,10 +48,14 @@ class CLASS_MailSender:
|
|
|
40
48
|
Pobj_Bcc: Optional[List[str]] = None,
|
|
41
49
|
Pobj_Attachments: Optional[List[str]] = None) -> MIMEMultipart:
|
|
42
50
|
"""
|
|
43
|
-
建立郵件內容(支援 HTML /
|
|
51
|
+
建立郵件內容(支援 HTML / 附件 / 顯示別名)
|
|
44
52
|
"""
|
|
45
53
|
msg = MIMEMultipart("alternative")
|
|
46
|
-
|
|
54
|
+
|
|
55
|
+
# 設定寄件者別名
|
|
56
|
+
from_addr = formataddr((Pms_From or self.Pms_Account, self.Pms_Account))
|
|
57
|
+
msg["From"] = from_addr
|
|
58
|
+
|
|
47
59
|
msg["To"] = ", ".join(Pobj_To or [])
|
|
48
60
|
if Pobj_Cc:
|
|
49
61
|
msg["Cc"] = ", ".join(Pobj_Cc)
|
|
@@ -56,7 +68,7 @@ class CLASS_MailSender:
|
|
|
56
68
|
if Pms_BodyHTML:
|
|
57
69
|
msg.attach(MIMEText(Pms_BodyHTML, "html", "utf-8"))
|
|
58
70
|
|
|
59
|
-
#
|
|
71
|
+
# 附件(支援中文檔名 & Outlook)
|
|
60
72
|
if Pobj_Attachments:
|
|
61
73
|
for ms_path in Pobj_Attachments:
|
|
62
74
|
try:
|
|
@@ -86,7 +98,6 @@ class CLASS_MailSender:
|
|
|
86
98
|
msg.attach(part)
|
|
87
99
|
except Exception as e:
|
|
88
100
|
print(f"⚠️ Can not add attachment: {ms_path} ({e})")
|
|
89
|
-
|
|
90
101
|
return msg
|
|
91
102
|
|
|
92
103
|
#------------------------------------------------------------
|
|
@@ -95,16 +106,18 @@ class CLASS_MailSender:
|
|
|
95
106
|
Pms_BodyText: str,
|
|
96
107
|
Pms_BodyHTML: Optional[str],
|
|
97
108
|
Pobj_To: List[str],
|
|
109
|
+
Pms_From: Optional[str] = None,
|
|
98
110
|
Pobj_Cc: Optional[List[str]] = None,
|
|
99
111
|
Pobj_Bcc: Optional[List[str]] = None,
|
|
100
112
|
Pobj_Attachments: Optional[List[str]] = None) -> bool:
|
|
101
113
|
"""
|
|
102
|
-
|
|
114
|
+
實際寄送郵件,支援寄件者別名
|
|
103
115
|
"""
|
|
104
116
|
msg = self.CUF_CreateMessage(
|
|
105
117
|
Pms_Subject=Pms_Subject,
|
|
106
118
|
Pms_BodyText=Pms_BodyText,
|
|
107
119
|
Pms_BodyHTML=Pms_BodyHTML,
|
|
120
|
+
Pms_From=Pms_From,
|
|
108
121
|
Pobj_To=Pobj_To,
|
|
109
122
|
Pobj_Cc=Pobj_Cc,
|
|
110
123
|
Pobj_Bcc=Pobj_Bcc,
|
|
@@ -112,47 +125,66 @@ class CLASS_MailSender:
|
|
|
112
125
|
)
|
|
113
126
|
|
|
114
127
|
all_recipients = (Pobj_To or []) + (Pobj_Cc or []) + (Pobj_Bcc or [])
|
|
128
|
+
from_addr = formataddr((Pms_From or self.Pms_Account, self.Pms_Account))
|
|
115
129
|
|
|
116
130
|
try:
|
|
117
131
|
if self.Pmb_UseSSL:
|
|
118
132
|
with smtplib.SMTP_SSL(self.Pms_SMTP_Server, self.Pmi_Port) as server:
|
|
119
133
|
server.login(self.Pms_Account, self.Pms_Password)
|
|
120
|
-
server.sendmail(
|
|
134
|
+
server.sendmail(from_addr, all_recipients, msg.as_string())
|
|
121
135
|
else:
|
|
122
136
|
with smtplib.SMTP(self.Pms_SMTP_Server, self.Pmi_Port) as server:
|
|
123
137
|
server.ehlo()
|
|
124
138
|
server.starttls()
|
|
125
139
|
server.login(self.Pms_Account, self.Pms_Password)
|
|
126
|
-
server.sendmail(
|
|
140
|
+
server.sendmail(from_addr, all_recipients, msg.as_string())
|
|
127
141
|
|
|
128
142
|
print("✅ Send Success!")
|
|
143
|
+
# ===== 觸發事件 =====
|
|
144
|
+
if self.OnAfterSendSuccess:
|
|
145
|
+
self.OnAfterSendSuccess(Pms_Subject)
|
|
129
146
|
return True
|
|
130
147
|
except Exception as e:
|
|
131
148
|
print("❌ Failure:", e)
|
|
149
|
+
# ===== 觸發事件 =====
|
|
150
|
+
if self.OnAfterSendFailure:
|
|
151
|
+
self.OnAfterSendFailure(str(e))
|
|
132
152
|
return False
|
|
133
153
|
|
|
134
|
-
|
|
135
154
|
# ================================================================================
|
|
136
155
|
# [範例]
|
|
137
156
|
# 匯入剛才寫好的 CLASS_MailSender
|
|
138
157
|
#from MailSender import CLASS_MailSender # 假設你把上面的 class 儲存為 MailSender.py
|
|
139
|
-
|
|
158
|
+
|
|
159
|
+
def GE_OnSendSuccess(Pms_Subject : str):
|
|
160
|
+
print("[事件]:成功寄出了!");
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def GE_OnSendFailure(Pms_ErrMsg : str):
|
|
164
|
+
print("[事件]: 寄送失敗 ...");
|
|
165
|
+
print("Err Msg:"+ Pms_ErrMsg);
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if(__name__ == "__main__"):
|
|
140
169
|
# === 初始化郵件傳送物件 ===
|
|
141
170
|
mailer = CLASS_MailSender(
|
|
142
|
-
Pms_SMTP_Server="
|
|
171
|
+
Pms_SMTP_Server="mxr.hxxxt.xxt",
|
|
143
172
|
Pmi_Port=465,
|
|
144
|
-
Pms_Account="
|
|
145
|
-
Pms_Password="
|
|
173
|
+
Pms_Account="xxxxch.xxz@xxa.xxxet.xxt",
|
|
174
|
+
Pms_Password="xxxxxxxxx",
|
|
146
175
|
Pmb_UseSSL=True
|
|
147
176
|
)
|
|
148
177
|
|
|
178
|
+
mailer.OnAfterSendSuccess = GE_OnSendSuccess;
|
|
179
|
+
mailer.OnAfterSendFailure = GE_OnSendFailure;
|
|
180
|
+
|
|
149
181
|
# === 郵件收件者設定 ===
|
|
150
|
-
ml_To = ["
|
|
151
|
-
ml_Cc = ["
|
|
152
|
-
ml_Bcc = ["
|
|
182
|
+
ml_To = ["gxxx4@goxxxx.bxz", "xxxxnxxx@xx27.xxxxx.xxt"]
|
|
183
|
+
ml_Cc = ["exxxxxx3@hotmail.com.tw"]
|
|
184
|
+
ml_Bcc = ["jxxxxxx.xxx@mxx.xxxet.xet"] # 密件副本,不會顯示在郵件中
|
|
153
185
|
|
|
154
186
|
# === 郵件主題與內容 ===
|
|
155
|
-
ms_Subject = "團隊週報通知"
|
|
187
|
+
ms_Subject = "團隊週報通知 有事件 wahaha 123*()F"
|
|
156
188
|
|
|
157
189
|
ms_BodyText = """
|
|
158
190
|
這是一封自動寄出的團隊週報通知。
|
|
@@ -178,8 +210,7 @@ if __name__ == "__main__":
|
|
|
178
210
|
|
|
179
211
|
# === 附件路徑 ===
|
|
180
212
|
ml_Attachments = [
|
|
181
|
-
"X:\\TEMP\\
|
|
182
|
-
"X:\\TEMP\\BOOK\\K9AKW4.jpg"
|
|
213
|
+
"X:\\TEMP\\112年縣檸檬幼申報收入.jpg"
|
|
183
214
|
]
|
|
184
215
|
|
|
185
216
|
# === 寄送 ===
|
|
@@ -187,6 +218,7 @@ if __name__ == "__main__":
|
|
|
187
218
|
Pms_Subject=ms_Subject,
|
|
188
219
|
Pms_BodyText=ms_BodyText,
|
|
189
220
|
Pms_BodyHTML=ms_BodyHTML,
|
|
221
|
+
Pms_From = "太棒了!!a會觸發事件",
|
|
190
222
|
Pobj_To=ml_To,
|
|
191
223
|
Pobj_Cc=ml_Cc,
|
|
192
224
|
Pobj_Bcc=ml_Bcc,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: UtilityLibAPI
|
|
3
|
-
Version: 1.2511.
|
|
3
|
+
Version: 1.2511.292
|
|
4
4
|
Summary: UtilityLibAPI Python package
|
|
5
5
|
Author-email: James Lin <tylin123@ms27.hinet.net>
|
|
6
6
|
License: Copyright (c) 2025 James Lin **UtilityLibAPI**
|
|
@@ -33,6 +33,13 @@ Dynamic: license-file
|
|
|
33
33
|
#UtilityLibAPI Classes
|
|
34
34
|
|
|
35
35
|
## History of version
|
|
36
|
+
Version 1.2511.292: 2025/11/29<BR>
|
|
37
|
+
Add Event for send mail when success or failure.
|
|
38
|
+
|
|
39
|
+
Version 1.2511.291: 2025/11/29<BR>
|
|
40
|
+
Fixed MailSenderLib: Attachement file name encode problem.
|
|
41
|
+
Add function for user can modify mail caption of from field.
|
|
42
|
+
|
|
36
43
|
Version 1.2511.282: 2025/11/27<BR>
|
|
37
44
|
Fixed MailSenderLib: Attachement file name encode problem.
|
|
38
45
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI.egg-info/requires.txt
RENAMED
|
File without changes
|
{utilitylibapi-1.2511.282 → utilitylibapi-1.2511.292}/src/UtilityLibAPI.egg-info/top_level.txt
RENAMED
|
File without changes
|