KyrosDev commited on
Commit
12235bc
·
1 Parent(s): a153e61

郵件內容自動將網址轉為可點擊連結

Browse files
Files changed (1) hide show
  1. app/services/email_service.py +14 -1
app/services/email_service.py CHANGED
@@ -75,11 +75,24 @@ class EmailService:
75
  logger.error(f"Get user emails error: {e}")
76
  return []
77
 
 
 
 
 
 
 
 
 
 
 
 
78
  def _format_email_html(self, content: str, product_type: str) -> str:
79
  """
80
  格式化郵件 HTML 內容
81
  """
82
- html_content = content.replace('\n', '<br>')
 
 
83
 
84
  if product_type == 'revit':
85
  header_title = 'KSTools Revit 版本更新'
 
75
  logger.error(f"Get user emails error: {e}")
76
  return []
77
 
78
+ def _auto_link_urls(self, text: str) -> str:
79
+ """
80
+ 將純文字網址轉換為可點擊的 HTML 連結
81
+ """
82
+ # 匹配 http:// 或 https:// 開頭的網址
83
+ url_pattern = re.compile(
84
+ r'(https?://[^\s<>"\']+)',
85
+ re.IGNORECASE
86
+ )
87
+ return url_pattern.sub(r'<a href="\1" style="color: #2563eb;">\1</a>', text)
88
+
89
  def _format_email_html(self, content: str, product_type: str) -> str:
90
  """
91
  格式化郵件 HTML 內容
92
  """
93
+ # 先轉換網址為連結,再處理換行
94
+ html_content = self._auto_link_urls(content)
95
+ html_content = html_content.replace('\n', '<br>')
96
 
97
  if product_type == 'revit':
98
  header_title = 'KSTools Revit 版本更新'