Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change TO STARTTLS #3

Merged
merged 1 commit into from
May 14, 2024
Merged
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
18 changes: 9 additions & 9 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ TESTING=False
ROOT_PATH=/palaute/

# Default receiver for feedback that has no home municipality or the sender refuses to say
DEFAULT_RECEIVER="[email protected]"
DEFAULT_RECEIVER=${DEFAULT_RECEIVER}
# A copy of the emails is always sent to this address
ALWAYS_RECIPIENT="[email protected]"
MAIL_SENDER="[email protected]"
ALWAYS_RECIPIENT=${ALWAYS_RECIPIENT}
MAIL_SENDER=${MAIL_SENDER}
BACKUP_FILE="feedback.backup"

# Location of the csv file that contains emails and municipality names.
EMAILS_CSV="emails.csv"

MAIL_SERVER="smtp.gmail.com"
MAIL_PORT=465
MAIL_USERNAME="usr"
MAIL_PASSWORD="pass"
MAIL_USE_TLS=False
MAIL_USE_SSL=True
MAIL_SERVER="smtp-mail.outlook.com"
MAIL_PORT="587"
MAIL_USERNAME=${MAIL_USERNAME}
MAIL_PASSWORD=${MAIL_PASSWORD}
MAIL_USE_TLS=True
MAIL_USE_SSL=True
5 changes: 3 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,16 @@ def send_email(subject, body, recipients, reply_to):
message["From"] = app.config["MAIL_SENDER"]
message["Subject"] = subject

context = ssl.create_default_context()
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
server = app.config["MAIL_SERVER"]
port = app.config["MAIL_PORT"]
sender_email = app.config["MAIL_SENDER"]
username = app.config["MAIL_USERNAME"]
password = app.config["MAIL_PASSWORD"]

try:
with smtplib.SMTP_SSL(server, port, context=context) as server:
with smtplib.SMTP(server, port) as server:
server.starttls(context=context)
server.login(username, password)
server.sendmail(sender_email, recipients, message.as_string())
except Exception as exception:
Expand Down