From 48708c73f43468ffe34206da44974eb0165ccb08 Mon Sep 17 00:00:00 2001 From: AlexCXC <1223408988@qq.com> Date: Tue, 15 Oct 2024 17:25:39 +0800 Subject: [PATCH 1/2] fix 163 smtp send-email --- dtable_events/dtable_io/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dtable_events/dtable_io/__init__.py b/dtable_events/dtable_io/__init__.py index b3548ded..5ea21799 100644 --- a/dtable_events/dtable_io/__init__.py +++ b/dtable_events/dtable_io/__init__.py @@ -709,7 +709,10 @@ def send_email_msg(auth_info, send_info, username, config=None, db_session=None) msg_obj.attach(attach_file) try: - smtp = smtplib.SMTP(email_host, int(email_port), timeout=30) + if 'smtp.163.com' in email_host: + smtp = smtplib.SMTP_SSL(email_host, int(email_port), timeout=30) + else: + smtp = smtplib.SMTP(email_host, int(email_port), timeout=30) except Exception as e: dtable_message_logger.warning( 'Email server configured failed. host: %s, port: %s, error: %s' % (email_host, email_port, e)) @@ -718,7 +721,8 @@ def send_email_msg(auth_info, send_info, username, config=None, db_session=None) success = False try: - smtp.starttls() + if 'smtp.163.com' not in email_host: + smtp.starttls() smtp.login(host_user, password) recevers = copy_to and send_to + copy_to or send_to smtp.sendmail(sender_email if sender_email else host_user, recevers, msg_obj.as_string()) From 37552eedaa020bd96ee4ef44ef7873f01a558403 Mon Sep 17 00:00:00 2001 From: AlexCXC <1223408988@qq.com> Date: Wed, 16 Oct 2024 11:37:45 +0800 Subject: [PATCH 2/2] opt fix 163 smtp --- dtable_events/dtable_io/__init__.py | 5 +++-- dtable_events/utils/constants.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dtable_events/dtable_io/__init__.py b/dtable_events/dtable_io/__init__.py index 5ea21799..301f85f4 100644 --- a/dtable_events/dtable_io/__init__.py +++ b/dtable_events/dtable_io/__init__.py @@ -37,6 +37,7 @@ from dtable_events.statistics.db import save_email_sending_records, batch_save_email_sending_records from dtable_events.data_sync.data_sync_utils import run_sync_emails from dtable_events.utils import get_inner_dtable_server_url, is_valid_email, uuid_str_to_36_chars +from dtable_events.utils.constants import SSL_SMTP_SERVICES from dtable_events.utils.dtable_server_api import DTableServerAPI, BaseExceedsException from dtable_events.utils.exception import ExcelFormatError from dtable_events.dtable_io.utils import clear_tmp_dir, clear_tmp_file, clear_tmp_files_and_dirs @@ -709,7 +710,7 @@ def send_email_msg(auth_info, send_info, username, config=None, db_session=None) msg_obj.attach(attach_file) try: - if 'smtp.163.com' in email_host: + if email_host in SSL_SMTP_SERVICES: smtp = smtplib.SMTP_SSL(email_host, int(email_port), timeout=30) else: smtp = smtplib.SMTP(email_host, int(email_port), timeout=30) @@ -721,7 +722,7 @@ def send_email_msg(auth_info, send_info, username, config=None, db_session=None) success = False try: - if 'smtp.163.com' not in email_host: + if not isinstance(smtp, smtplib.SMTP_SSL): smtp.starttls() smtp.login(host_user, password) recevers = copy_to and send_to + copy_to or send_to diff --git a/dtable_events/utils/constants.py b/dtable_events/utils/constants.py index feff756c..3b1a8a40 100644 --- a/dtable_events/utils/constants.py +++ b/dtable_events/utils/constants.py @@ -237,3 +237,7 @@ class MapLevel: {'color': '#46A1FD', 'border_color': '#3C8FE4', 'text_color': '#FFFFFF'}, {'color': '#C2C2C2', 'border_color': '#ADADAD', 'text_color': '#FFFFFF'}, ] + +SSL_SMTP_SERVICES = [ + 'smtp.163.com' +]