UtilityLibAPI 1.2511.282__tar.gz → 1.2511.291__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.2511.282/src/UtilityLibAPI.egg-info → utilitylibapi-1.2511.291}/PKG-INFO +5 -1
  2. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/README.md +4 -0
  3. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/pyproject.toml +1 -1
  4. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI/MailSenderLib.py +28 -21
  5. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291/src/UtilityLibAPI.egg-info}/PKG-INFO +5 -1
  6. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/LICENSE +0 -0
  7. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/setup.cfg +0 -0
  8. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI/Archive7zLib.py +0 -0
  9. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI/EnDeCodeLib.py +0 -0
  10. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI/ExtWrapper7zLib.py +0 -0
  11. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI/SessionVARLib.py +0 -0
  12. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI/__init__.py +0 -0
  13. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI.egg-info/SOURCES.txt +0 -0
  14. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI.egg-info/dependency_links.txt +0 -0
  15. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/src/UtilityLibAPI.egg-info/requires.txt +0 -0
  16. {utilitylibapi-1.2511.282 → utilitylibapi-1.2511.291}/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.282
3
+ Version: 1.2511.291
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.2511.291: 2025/11/29<BR>
37
+ Fixed MailSenderLib: Attachement file name encode problem.
38
+ Add function for user can modify mail caption of from field.
39
+
36
40
  Version 1.2511.282: 2025/11/27<BR>
37
41
  Fixed MailSenderLib: Attachement file name encode problem.
38
42
 
@@ -1,6 +1,10 @@
1
1
  #UtilityLibAPI Classes
2
2
 
3
3
  ## History of version
4
+ Version 1.2511.291: 2025/11/29<BR>
5
+ Fixed MailSenderLib: Attachement file name encode problem.
6
+ Add function for user can modify mail caption of from field.
7
+
4
8
  Version 1.2511.282: 2025/11/27<BR>
5
9
  Fixed MailSenderLib: Attachement file name encode problem.
6
10
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "UtilityLibAPI"
7
- version = "1.2511.282"
7
+ version = "1.2511.291"
8
8
  description = "UtilityLibAPI Python package"
9
9
  authors = [
10
10
  { name="James Lin", email="tylin123@ms27.hinet.net" }
@@ -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,10 @@ 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 = Pmi_Port
28
- self.Pms_Account = Pms_Account
29
- self.Pms_Password = Pms_Password
30
- self.Pmb_UseSSL = 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
31
33
 
32
34
  #------------------------------------------------------------
33
35
  def CUF_CreateMessage(self,
@@ -40,10 +42,14 @@ class CLASS_MailSender:
40
42
  Pobj_Bcc: Optional[List[str]] = None,
41
43
  Pobj_Attachments: Optional[List[str]] = None) -> MIMEMultipart:
42
44
  """
43
- 建立郵件內容(支援 HTML / 附件)
45
+ 建立郵件內容(支援 HTML / 附件 / 顯示別名)
44
46
  """
45
47
  msg = MIMEMultipart("alternative")
46
- msg["From"] = formataddr((Pms_From or self.Pms_Account, self.Pms_Account))
48
+
49
+ # 設定寄件者別名
50
+ from_addr = formataddr((Pms_From or self.Pms_Account, self.Pms_Account))
51
+ msg["From"] = from_addr
52
+
47
53
  msg["To"] = ", ".join(Pobj_To or [])
48
54
  if Pobj_Cc:
49
55
  msg["Cc"] = ", ".join(Pobj_Cc)
@@ -56,7 +62,7 @@ class CLASS_MailSender:
56
62
  if Pms_BodyHTML:
57
63
  msg.attach(MIMEText(Pms_BodyHTML, "html", "utf-8"))
58
64
 
59
- # 附件
65
+ # 附件(支援中文檔名 & Outlook)
60
66
  if Pobj_Attachments:
61
67
  for ms_path in Pobj_Attachments:
62
68
  try:
@@ -86,7 +92,6 @@ class CLASS_MailSender:
86
92
  msg.attach(part)
87
93
  except Exception as e:
88
94
  print(f"⚠️ Can not add attachment: {ms_path} ({e})")
89
-
90
95
  return msg
91
96
 
92
97
  #------------------------------------------------------------
@@ -95,16 +100,18 @@ class CLASS_MailSender:
95
100
  Pms_BodyText: str,
96
101
  Pms_BodyHTML: Optional[str],
97
102
  Pobj_To: List[str],
103
+ Pms_From: Optional[str] = None,
98
104
  Pobj_Cc: Optional[List[str]] = None,
99
105
  Pobj_Bcc: Optional[List[str]] = None,
100
106
  Pobj_Attachments: Optional[List[str]] = None) -> bool:
101
107
  """
102
- 實際寄送郵件
108
+ 實際寄送郵件,支援寄件者別名
103
109
  """
104
110
  msg = self.CUF_CreateMessage(
105
111
  Pms_Subject=Pms_Subject,
106
112
  Pms_BodyText=Pms_BodyText,
107
113
  Pms_BodyHTML=Pms_BodyHTML,
114
+ Pms_From=Pms_From,
108
115
  Pobj_To=Pobj_To,
109
116
  Pobj_Cc=Pobj_Cc,
110
117
  Pobj_Bcc=Pobj_Bcc,
@@ -112,18 +119,19 @@ class CLASS_MailSender:
112
119
  )
113
120
 
114
121
  all_recipients = (Pobj_To or []) + (Pobj_Cc or []) + (Pobj_Bcc or [])
122
+ from_addr = formataddr((Pms_From or self.Pms_Account, self.Pms_Account))
115
123
 
116
124
  try:
117
125
  if self.Pmb_UseSSL:
118
126
  with smtplib.SMTP_SSL(self.Pms_SMTP_Server, self.Pmi_Port) as server:
119
127
  server.login(self.Pms_Account, self.Pms_Password)
120
- server.sendmail(self.Pms_Account, all_recipients, msg.as_string())
128
+ server.sendmail(from_addr, all_recipients, msg.as_string())
121
129
  else:
122
130
  with smtplib.SMTP(self.Pms_SMTP_Server, self.Pmi_Port) as server:
123
131
  server.ehlo()
124
132
  server.starttls()
125
133
  server.login(self.Pms_Account, self.Pms_Password)
126
- server.sendmail(self.Pms_Account, all_recipients, msg.as_string())
134
+ server.sendmail(from_addr, all_recipients, msg.as_string())
127
135
 
128
136
  print("✅ Send Success!")
129
137
  return True
@@ -131,7 +139,6 @@ class CLASS_MailSender:
131
139
  print("❌ Failure:", e)
132
140
  return False
133
141
 
134
-
135
142
  # ================================================================================
136
143
  # [範例]
137
144
  # 匯入剛才寫好的 CLASS_MailSender
@@ -139,20 +146,20 @@ class CLASS_MailSender:
139
146
  if __name__ == "__main__":
140
147
  # === 初始化郵件傳送物件 ===
141
148
  mailer = CLASS_MailSender(
142
- Pms_SMTP_Server="msr.xxxx.net",
149
+ Pms_SMTP_Server="msr.hinet.net",
143
150
  Pmi_Port=465,
144
- Pms_Account="xxx.biz@xx.hxxxt.net",
145
- Pms_Password="xxxxx*",
151
+ Pms_Account="gxxxx.xz@msa.hinet.net",
152
+ Pms_Password="xxxxx",
146
153
  Pmb_UseSSL=True
147
154
  )
148
155
 
149
156
  # === 郵件收件者設定 ===
150
- ml_To = ["gt504@gxxxxxh.biz", "txxxxx@ms27.xxxt.net"]
151
- ml_Cc = ["ebooxxx3@hotmail.com.tw"]
152
- ml_Bcc = ["xxxxsty.lin@xxx.hinet.net"] # 密件副本,不會顯示在郵件中
157
+ ml_To = ["xxxx4@xxxxxh.xxz", "xxxxxx23@xxx7.hxxxx.net"]
158
+ ml_Cc = ["exxxxx03@hotmail.com.tw"]
159
+ ml_Bcc = ["xxxxxxy.lin@msa.hxxxx.net"] # 密件副本,不會顯示在郵件中
153
160
 
154
161
  # === 郵件主題與內容 ===
155
- ms_Subject = "團隊週報通知"
162
+ ms_Subject = "團隊週報通知 wahaha 123*()F"
156
163
 
157
164
  ms_BodyText = """
158
165
  這是一封自動寄出的團隊週報通知。
@@ -178,8 +185,7 @@ if __name__ == "__main__":
178
185
 
179
186
  # === 附件路徑 ===
180
187
  ml_Attachments = [
181
- "X:\\TEMP\\BOOK\\RCR6000_匯出外部資料_RCR6000EXT_XXX.pdf",
182
- "X:\\TEMP\\BOOK\\K9AKW4.jpg"
188
+ "X:\\TEMP\\112年縣檸檬幼申報收入.jpg"
183
189
  ]
184
190
 
185
191
  # === 寄送 ===
@@ -187,6 +193,7 @@ if __name__ == "__main__":
187
193
  Pms_Subject=ms_Subject,
188
194
  Pms_BodyText=ms_BodyText,
189
195
  Pms_BodyHTML=ms_BodyHTML,
196
+ Pms_From = "太棒了!!abcdefg123",
190
197
  Pobj_To=ml_To,
191
198
  Pobj_Cc=ml_Cc,
192
199
  Pobj_Bcc=ml_Bcc,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: UtilityLibAPI
3
- Version: 1.2511.282
3
+ Version: 1.2511.291
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.2511.291: 2025/11/29<BR>
37
+ Fixed MailSenderLib: Attachement file name encode problem.
38
+ Add function for user can modify mail caption of from field.
39
+
36
40
  Version 1.2511.282: 2025/11/27<BR>
37
41
  Fixed MailSenderLib: Attachement file name encode problem.
38
42