fix: smtp_proxy_server support decode from mail charset (#223)

This commit is contained in:
Dream Hunter
2024-05-10 23:08:38 +08:00
committed by GitHub
parent 46e04fd94a
commit 386441a743
+3 -2
View File
@@ -51,6 +51,7 @@ class CustomSMTPHandler:
if msg.is_multipart(): if msg.is_multipart():
for part in msg.walk(): for part in msg.walk():
content_type = part.get_content_type() content_type = part.get_content_type()
charset = part.get_content_charset()
payload = part.get_payload(decode=True) payload = part.get_payload(decode=True)
if content_type not in ["text/plain", "text/html"]: if content_type not in ["text/plain", "text/html"]:
_logger.warning(f"Skipping {content_type}") _logger.warning(f"Skipping {content_type}")
@@ -59,7 +60,7 @@ class CustomSMTPHandler:
continue continue
content_list.append({ content_list.append({
"type": content_type, "type": content_type,
"value": payload.decode() "value": payload.decode(charset)
}) })
elif msg.get_content_type() in ["text/plain", "text/html"] and msg.get_payload(decode=True): elif msg.get_content_type() in ["text/plain", "text/html"] and msg.get_payload(decode=True):
content_list.append({ content_list.append({
@@ -97,7 +98,7 @@ class CustomSMTPHandler:
"is_html": body["type"] == "text/html", "is_html": body["type"] == "text/html",
"content": body["value"], "content": body["value"],
} }
_logger.info(f"Send mail {send_body}") _logger.info(f"Send mail {dict(send_body, token='***')}")
try: try:
res = requests.post( res = requests.post(
f"{settings.proxy_url}/external/api/send_mail", f"{settings.proxy_url}/external/api/send_mail",