Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Introduced Safer SMTP Alternative: Added SMTP_SSL #846

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 0 additions & 2 deletions apps/common/src/python/mediawords/util/config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,11 @@ def port() -> int:
@staticmethod
def use_starttls() -> bool:
"""Use STARTTLS? If you enable that, you probably want to change the port to 587."""
# FIXME remove altogether, not used
return False

@staticmethod
def username() -> str:
"""Username."""
# FIXME remove, not used
return ''

@staticmethod
Expand Down
21 changes: 16 additions & 5 deletions apps/common/src/python/mediawords/util/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,22 @@ def send_email(message: Message) -> bool:

else:

# Connect to SMTP
smtp = smtplib.SMTP(
host=CommonConfig.smtp().hostname(),
port=CommonConfig.smtp().port(),
)
# Connect to SMTP_SSL
if CommonConfig.smtp().use_starttls():
smtp = smtplib.SMTP_SSL(
host=CommonConfig.smtp().hostname(),
port=CommonConfig.smtp().port(),
)
smtp.login(
user=CommonConfig.smtp().username(),
password=CommonConfig.smtp().password(),
)
else:
# Connect to SMTP
smtp = smtplib.SMTP(
host=CommonConfig.smtp().hostname(),
port=CommonConfig.smtp().port(),
)

# Send message
refused_recipients = smtp.sendmail(mime_message['From'], mime_message['To'], mime_message.as_string())
Expand Down