Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dtable_events/dtable_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -709,7 +710,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 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)
except Exception as e:
dtable_message_logger.warning(
'Email server configured failed. host: %s, port: %s, error: %s' % (email_host, email_port, e))
Expand All @@ -718,7 +722,8 @@ def send_email_msg(auth_info, send_info, username, config=None, db_session=None)
success = False

try:
smtp.starttls()
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
smtp.sendmail(sender_email if sender_email else host_user, recevers, msg_obj.as_string())
Expand Down
4 changes: 4 additions & 0 deletions dtable_events/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Loading