UtilityLibAPI 1.2512.502__tar.gz → 1.2512.801__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.
Files changed (16) hide show
  1. {utilitylibapi-1.2512.502/src/UtilityLibAPI.egg-info → utilitylibapi-1.2512.801}/PKG-INFO +5 -1
  2. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/README.md +4 -0
  3. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/pyproject.toml +1 -1
  4. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI/MailSenderLib.py +84 -13
  5. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801/src/UtilityLibAPI.egg-info}/PKG-INFO +5 -1
  6. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/LICENSE +0 -0
  7. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/setup.cfg +0 -0
  8. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI/Archive7zLib.py +0 -0
  9. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI/EnDeCodeLib.py +0 -0
  10. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI/ExtWrapper7zLib.py +0 -0
  11. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI/SessionVARLib.py +0 -0
  12. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI/__init__.py +0 -0
  13. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI.egg-info/SOURCES.txt +0 -0
  14. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI.egg-info/dependency_links.txt +0 -0
  15. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/src/UtilityLibAPI.egg-info/requires.txt +0 -0
  16. {utilitylibapi-1.2512.502 → utilitylibapi-1.2512.801}/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.2512.502
3
+ Version: 1.2512.801
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,10 @@ Dynamic: license-file
33
33
  #UtilityLibAPI Classes
34
34
 
35
35
  ## History of version
36
+ Version 1.2512.0801: 2025/12/08<BR>
37
+ Modify CUF_Open() function for multi user accounts.
38
+
39
+
36
40
  Version 1.2512.0501: 2025/12/05<BR>
37
41
  Fixed break down when smtp server not auth or response time out.
38
42
 
@@ -1,6 +1,10 @@
1
1
  #UtilityLibAPI Classes
2
2
 
3
3
  ## History of version
4
+ Version 1.2512.0801: 2025/12/08<BR>
5
+ Modify CUF_Open() function for multi user accounts.
6
+
7
+
4
8
  Version 1.2512.0501: 2025/12/05<BR>
5
9
  Fixed break down when smtp server not auth or response time out.
6
10
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "UtilityLibAPI"
7
- version = "1.2512.0502"
7
+ version = "1.2512.0801"
8
8
  description = "UtilityLibAPI Python package"
9
9
  authors = [
10
10
  { name="James Lin", email="tylin123@ms27.hinet.net" }
@@ -25,16 +25,88 @@ class CLASS_MailSender:
25
25
  :param Pms_Password: 登入密碼或應用程式密碼
26
26
  :param Pmb_UseSSL: 是否使用 SSL 連線 (預設 True)
27
27
  """
28
- self.Pms_SMTP_Server = Pms_SMTP_Server
29
- self.Pmi_Port = Pmi_Port
30
- self.Pms_Account = Pms_Account
31
- self.Pms_Password = Pms_Password
32
- self.Pmb_UseSSL = Pmb_UseSSL
28
+ self.CVms_SMTP_Server = Pms_SMTP_Server
29
+ self.CVmi_Port = Pmi_Port
30
+ self.CVms_Account = Pms_Account # 登入帳號
31
+ self.CVms_Password = Pms_Password # 登入密碼
32
+ self.CVmb_UseSSL = Pmb_UseSSL
33
33
  # ======================================================================
34
34
  # 新增事件
35
35
  # ======================================================================
36
36
  self.OnAfterSendSuccess: Optional[Callable[[str], None]] = None
37
37
  self.OnAfterSendFailure: Optional[Callable[[str], None]] = None
38
+ # ============================================================
39
+ # ⭐⭐ 新增:維持 SMTP 連線用變數
40
+ # ============================================================
41
+ self.CVobj_Server: Optional[smtplib.SMTP] = None
42
+
43
+ # ################################################################################
44
+ # [預防 Mail Server 中斷連線]
45
+ # 手動控制連線
46
+ # mailer.CUF_Open()
47
+ # mailer.CUF_SendMail(...)
48
+ # mailer.CUF_Close()
49
+ # ------------------------------------------------------------
50
+ # 每 5 分鐘預防性重連
51
+ # mailer.CUF_Reconnect()
52
+ # ------------------------------------------------------------
53
+ # 如果 SendMail 失敗,要重連
54
+ # if not mailer.CUF_SendMail(...):
55
+ # mailer.CUF_Reconnect()
56
+ # ################################################################################
57
+
58
+ # ================================================================================
59
+ # ⭐⭐⭐ 新增函數:CUF_Open() ⭐⭐⭐
60
+ # ================================================================================
61
+ def CUF_Open(self, Pms_Account:str, Pms_PassWD:str) -> bool:
62
+ """建立 SMTP 連線(長連線模式)"""
63
+ self.CVms_Account = Pms_Account;
64
+ self.CVms_Password = Pms_PassWD;
65
+ # ------------------------------------------------------------
66
+ try:
67
+ if self.CVobj_Server:
68
+ return True
69
+
70
+ if self.CVmb_UseSSL:
71
+ server = smtplib.SMTP_SSL(self.CVms_SMTP_Server, self.CVmi_Port)
72
+ else:
73
+ server = smtplib.SMTP(self.CVms_SMTP_Server, self.CVmi_Port)
74
+ server.ehlo()
75
+ server.starttls()
76
+
77
+ server.login(self.CVms_Account, self.CVms_Password)
78
+ self.CVobj_Server = server
79
+ return True
80
+ except Exception as e:
81
+ print("❌ CUF_Open Error:", e)
82
+ self.CVobj_Server = None
83
+ return False
84
+
85
+
86
+ # ================================================================================
87
+ # ⭐⭐⭐ 新增函數:CUF_Close() ⭐⭐⭐
88
+ # ================================================================================
89
+ def CUF_Close(self):
90
+ """關閉 SMTP 長連線"""
91
+ try:
92
+ if self.CVobj_Server:
93
+ try:
94
+ self.CVobj_Server.quit()
95
+ except:
96
+ pass
97
+ self.CVobj_Server = None
98
+ except:
99
+ self.CVobj_Server = None
100
+
101
+
102
+ # ================================================================================
103
+ # ⭐⭐⭐ 新增函數:CUF_Reconnect() ⭐⭐⭐
104
+ # ================================================================================
105
+ def CUF_Reconnect(self) -> bool:
106
+ """強制重新連線"""
107
+ self.CUF_Close()
108
+ return self.CUF_Open(Pms_Account = self.CVms_Account,
109
+ Pms_PassWD = self.CVms_Password);
38
110
 
39
111
 
40
112
  #------------------------------------------------------------
@@ -53,7 +125,7 @@ class CLASS_MailSender:
53
125
  msg = MIMEMultipart("alternative")
54
126
 
55
127
  # 設定寄件者別名
56
- from_addr = formataddr((Pms_From or self.Pms_Account, self.Pms_Account))
128
+ from_addr = formataddr((Pms_From or self.CVms_Account, self.CVms_Account))
57
129
  msg["From"] = from_addr
58
130
 
59
131
  msg["To"] = ", ".join(Pobj_To or [])
@@ -125,18 +197,18 @@ class CLASS_MailSender:
125
197
  )
126
198
 
127
199
  all_recipients = (Pobj_To or []) + (Pobj_Cc or []) + (Pobj_Bcc or [])
128
- from_addr = formataddr((Pms_From or self.Pms_Account, self.Pms_Account))
200
+ from_addr = formataddr((Pms_From or self.CVms_Account, self.CVms_Account))
129
201
 
130
202
  try:
131
- if self.Pmb_UseSSL:
132
- with smtplib.SMTP_SSL(self.Pms_SMTP_Server, self.Pmi_Port) as server:
133
- server.login(self.Pms_Account, self.Pms_Password)
203
+ if self.CVmb_UseSSL:
204
+ with smtplib.SMTP_SSL(self.CVms_SMTP_Server, self.CVmi_Port) as server:
205
+ server.login(self.CVms_Account, self.CVms_Password)
134
206
  server.sendmail(from_addr, all_recipients, msg.as_string())
135
207
  else:
136
- with smtplib.SMTP(self.Pms_SMTP_Server, self.Pmi_Port) as server:
208
+ with smtplib.SMTP(self.CVms_SMTP_Server, self.CVmi_Port) as server:
137
209
  server.ehlo()
138
210
  server.starttls()
139
- server.login(self.Pms_Account, self.Pms_Password)
211
+ server.login(self.CVms_Account, self.CVms_Password)
140
212
  server.sendmail(from_addr, all_recipients, msg.as_string())
141
213
 
142
214
  print("✅ Send Success!")
@@ -152,7 +224,6 @@ class CLASS_MailSender:
152
224
  return False
153
225
 
154
226
 
155
-
156
227
  # ================================================================================
157
228
  # [範例]
158
229
  # 匯入剛才寫好的 CLASS_MailSender
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: UtilityLibAPI
3
- Version: 1.2512.502
3
+ Version: 1.2512.801
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,10 @@ Dynamic: license-file
33
33
  #UtilityLibAPI Classes
34
34
 
35
35
  ## History of version
36
+ Version 1.2512.0801: 2025/12/08<BR>
37
+ Modify CUF_Open() function for multi user accounts.
38
+
39
+
36
40
  Version 1.2512.0501: 2025/12/05<BR>
37
41
  Fixed break down when smtp server not auth or response time out.
38
42