Functions-d 1.2.3__tar.gz → 1.2.5__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.
- {functions_d-1.2.3 → functions_d-1.2.5}/Functions_d/Functions_d.py +112 -20
- {functions_d-1.2.3 → functions_d-1.2.5}/Functions_d.egg-info/PKG-INFO +1 -1
- {functions_d-1.2.3 → functions_d-1.2.5}/PKG-INFO +1 -1
- {functions_d-1.2.3 → functions_d-1.2.5}/setup.cfg +1 -1
- {functions_d-1.2.3 → functions_d-1.2.5}/Functions_d/__init__.py +0 -0
- {functions_d-1.2.3 → functions_d-1.2.5}/Functions_d.egg-info/SOURCES.txt +0 -0
- {functions_d-1.2.3 → functions_d-1.2.5}/Functions_d.egg-info/dependency_links.txt +0 -0
- {functions_d-1.2.3 → functions_d-1.2.5}/Functions_d.egg-info/requires.txt +0 -0
- {functions_d-1.2.3 → functions_d-1.2.5}/Functions_d.egg-info/top_level.txt +0 -0
- {functions_d-1.2.3 → functions_d-1.2.5}/README.md +0 -0
- {functions_d-1.2.3 → functions_d-1.2.5}/pyproject.toml +0 -0
- {functions_d-1.2.3 → functions_d-1.2.5}/setup.py +0 -0
|
@@ -319,26 +319,116 @@ class DataProcessingAndMessaging:
|
|
|
319
319
|
return result
|
|
320
320
|
|
|
321
321
|
# -------------------------- 发送邮件(旧版) --------------------------
|
|
322
|
-
def sende_email(self, name, contact_name, title, rec, file, cc=
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
322
|
+
def sende_email(self, name, contact_name, title, rec, file=None, cc=None, bcc=None, remarks=None):
|
|
323
|
+
"""
|
|
324
|
+
简洁版邮件发送(支持重复调用,自动过滤无效参数)
|
|
325
|
+
:param name: 收件人称呼(如"各位")
|
|
326
|
+
:param contact_name: 联系人姓名(如"董养")
|
|
327
|
+
:param title: 邮件主题
|
|
328
|
+
:param rec: 收件人邮箱(单个字符串或列表)
|
|
329
|
+
:param file: 附件路径(单个字符串、列表,或None)
|
|
330
|
+
:param cc: 抄送邮箱(单个字符串、列表,或None)
|
|
331
|
+
:param bcc: 密送邮箱(单个字符串、列表,或None)
|
|
332
|
+
:param remarks: 附加备注(可选,默认None,传入文本字符串时追加到正文)
|
|
333
|
+
"""
|
|
334
|
+
|
|
335
|
+
# 1. 内部工具:格式化邮箱(转列表+过滤无效值)
|
|
336
|
+
def format_email(emails):
|
|
337
|
+
if not emails:
|
|
338
|
+
return None
|
|
339
|
+
# 单个邮箱转列表,列表直接使用
|
|
340
|
+
email_list = [emails] if isinstance(emails, str) else emails
|
|
341
|
+
# 过滤:非空字符串 + 简单格式校验(含@和.)
|
|
342
|
+
valid_emails = [
|
|
343
|
+
e.strip() for e in email_list
|
|
344
|
+
if isinstance(e, str) and e.strip() and '@' in e.strip() and '.' in e.strip()
|
|
345
|
+
]
|
|
346
|
+
return valid_emails if valid_emails else None
|
|
347
|
+
|
|
348
|
+
# 2. 格式化所有邮箱参数
|
|
349
|
+
to_emails = format_email(rec)
|
|
350
|
+
cc_emails = format_email(cc)
|
|
351
|
+
bcc_emails = format_email(bcc)
|
|
352
|
+
|
|
353
|
+
# 3. 核心参数校验(提前报错,避免无效连接)
|
|
354
|
+
if not to_emails:
|
|
355
|
+
err_msg = "邮件发送失败:无有效收件人邮箱"
|
|
356
|
+
self.logger.error(err_msg)
|
|
357
|
+
raise ValueError(err_msg)
|
|
358
|
+
if not title.strip():
|
|
359
|
+
err_msg = "邮件发送失败:邮件主题不能为空"
|
|
360
|
+
self.logger.error(err_msg)
|
|
361
|
+
raise ValueError(err_msg)
|
|
362
|
+
|
|
363
|
+
# 4. 附件处理(校验存在性,支持单个/列表)
|
|
364
|
+
attachments = None
|
|
365
|
+
if file:
|
|
366
|
+
file_list = [file] if isinstance(file, str) else file
|
|
367
|
+
attachments = []
|
|
368
|
+
for f in file_list:
|
|
369
|
+
f = f.strip()
|
|
370
|
+
if not os.path.exists(f):
|
|
371
|
+
err_msg = f"邮件发送失败:附件不存在 -> {f}"
|
|
372
|
+
self.logger.error(err_msg)
|
|
373
|
+
raise FileNotFoundError(err_msg)
|
|
374
|
+
attachments.append(f)
|
|
375
|
+
|
|
376
|
+
# 5. SMTP固定配置(重复调用无需修改)
|
|
377
|
+
smtp_conf = {
|
|
378
|
+
"user": 'cc_yingxiao@xin.com',
|
|
379
|
+
"password": 'cw46pfeznNQx',
|
|
380
|
+
"host": 'mail.xin.com',
|
|
381
|
+
"port": 587,
|
|
382
|
+
"smtp_ssl": False,
|
|
383
|
+
"smtp_starttls": True
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
# 6. 邮件内容(新增remarks逻辑:有值则追加到"请查收!"下方,保持缩进一致)
|
|
387
|
+
email_content = f"{name} 好:\n附件为《{title}》,请查收!"
|
|
388
|
+
if remarks and isinstance(remarks, str) and remarks.strip():
|
|
389
|
+
formatted_remarks = remarks.strip().replace('\n', '\n') # 处理多行备注
|
|
390
|
+
email_content += f"\n{formatted_remarks}"
|
|
391
|
+
email_content += f"\n\n如有疑问请联系{contact_name},谢谢~"
|
|
392
|
+
|
|
328
393
|
try:
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
394
|
+
# 上下文管理器:自动关闭连接,重复调用不泄露资源
|
|
395
|
+
with yagmail.SMTP(**smtp_conf) as yag:
|
|
396
|
+
yag.send(
|
|
397
|
+
to=to_emails,
|
|
398
|
+
subject=title.strip(),
|
|
399
|
+
contents=email_content,
|
|
400
|
+
attachments=attachments,
|
|
401
|
+
cc=cc_emails,
|
|
402
|
+
bcc=bcc_emails
|
|
403
|
+
)
|
|
404
|
+
# 简洁日志:关键信息+统计,便于排查
|
|
405
|
+
log_msg = f"邮件发送成功 | 主题:{title.strip()} | 收件人:{len(to_emails)}人"
|
|
406
|
+
if cc_emails:
|
|
407
|
+
log_msg += f" | 抄送:{len(cc_emails)}人"
|
|
408
|
+
if bcc_emails:
|
|
409
|
+
log_msg += f" | 密送:{len(bcc_emails)}人"
|
|
410
|
+
if attachments:
|
|
411
|
+
log_msg += f" | 附件:{len(attachments)}个"
|
|
412
|
+
if remarks and remarks.strip():
|
|
413
|
+
log_msg += f" | 包含备注:{remarks.strip()[:20]}..." # 日志显示备注前20字(避免过长)
|
|
414
|
+
self.logger.info(log_msg)
|
|
415
|
+
print(log_msg)
|
|
416
|
+
|
|
417
|
+
# 7. 分类异常捕获(易排查问题)
|
|
418
|
+
except yagmail.SMTPAuthenticationError:
|
|
419
|
+
err_msg = "邮件发送失败:SMTP账号/密码/授权码错误"
|
|
420
|
+
self.logger.error(err_msg)
|
|
421
|
+
raise ValueError(err_msg)
|
|
422
|
+
except yagmail.SMTPConnectionError:
|
|
423
|
+
err_msg = "邮件发送失败:SMTP服务器连接失败(检查host/port/防火墙)"
|
|
424
|
+
self.logger.error(err_msg)
|
|
425
|
+
raise ConnectionError(err_msg)
|
|
426
|
+
except FileNotFoundError:
|
|
427
|
+
raise # 附件错误已提前处理,直接抛出
|
|
339
428
|
except Exception as e:
|
|
340
|
-
|
|
341
|
-
|
|
429
|
+
err_msg = f"邮件发送失败:{str(e)}"
|
|
430
|
+
self.logger.error(err_msg, exc_info=True)
|
|
431
|
+
raise RuntimeError(err_msg)
|
|
342
432
|
|
|
343
433
|
# 新增:提取Hive核心错误信息方法
|
|
344
434
|
def extract_core_hive_error(self, err_msg):
|
|
@@ -938,8 +1028,9 @@ class DataProcessingAndMessaging:
|
|
|
938
1028
|
self._wechat_doc_log(error_msg)
|
|
939
1029
|
raise Exception(error_msg)
|
|
940
1030
|
docid = result.get("docid")
|
|
941
|
-
self._wechat_doc_log(f"
|
|
942
|
-
|
|
1031
|
+
self._wechat_doc_log(f"智能表格:{sheet_name} 创建成功,docid={docid}")
|
|
1032
|
+
print(f"智能表格:{sheet_name} 创建成功,docid={docid}")
|
|
1033
|
+
return {"智能表格": sheet_name, "docid": docid, "url": result.get("url")}
|
|
943
1034
|
except Exception as e:
|
|
944
1035
|
self._wechat_doc_log(f"创建异常: {str(e)}")
|
|
945
1036
|
raise
|
|
@@ -1119,6 +1210,7 @@ class DataProcessingAndMessaging:
|
|
|
1119
1210
|
raise Exception(error_msg)
|
|
1120
1211
|
|
|
1121
1212
|
self._wechat_doc_log(f"文档删除成功:docid={docid}")
|
|
1213
|
+
print(f"文档删除成功:docid={docid}")
|
|
1122
1214
|
return True
|
|
1123
1215
|
|
|
1124
1216
|
# -------------------------- 辅助方法:检查文件是否被占用 --------------------------
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|