Skip to content

Commit

Permalink
Merge pull request #3 from NatLibFi/outlook
Browse files Browse the repository at this point in the history
change TO STARTTLS
  • Loading branch information
natlibfi-max-grasbeck authored May 14, 2024
2 parents 9d621b9 + c4cf126 commit 4f5b46c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
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

0 comments on commit 4f5b46c

Please sign in to comment.