# HG changeset patch # User Dennis Fink # Date 2022-06-26 11:29:38 # Node ID 856635b4eef4e71dc2f35ba7a638848c6e10d071 # Parent 964b9fccf7599b68c1d74edd8dc03d15690122f6 Apply consistent style and use values from config in post_email diff --git a/spaceapi/utils.py b/spaceapi/utils.py --- a/spaceapi/utils.py +++ b/spaceapi/utils.py @@ -1,8 +1,8 @@ +import email import json import os.path import random import smtplib -import email from functools import wraps from time import time @@ -74,16 +74,20 @@ def post_toot(toot): def post_email(subject, body): if "EMAIL_PASS" in current_app.config: - smtpConn = smtplib.SMTP("EMAIL_HOST", port="EMAIL_PORT") - sslContext = ssl.create_default_context(Purpose.SERVER_AUTH) - smtpConn.starttls(sslContext) - smtpConn.login("EMAIL_USER", "EMAIL_PASS") + smtp_conn = smtplib.SMTP( + current_app.config["EMAIL_HOST"], port=current_app.config["EMAIL_PORT"] + ) + ssl_context = ssl.create_default_context(Purpose.SERVER_AUTH) + smtp_conn.starttls(ssl_context) + smtp_conn.login( + current_app.config["EMAIL_USER"], current_app.config["EMAIL_PASS"] + ) msg = email.message.EmailMessage(email.policy.SMTP) - msg['To'] = "EMAIL_ANNOUNCE_ADDRESS" - msg['From'] = "EMAIL_USER" - msg['Subject'] = subject + msg["To"] = current_app.config["EMAIL_ANNOUNCE_ADDRESS"] + msg["From"] = current_app.config["EMAIL_USER"] + msg["Subject"] = subject msg.set_content(body) - smtpConn.send_message(msg) + smtp_conn.send_message(msg) class Singleton: @@ -193,11 +197,7 @@ class ActiveStatusv14(Singleton, dict): current_app.logger.error("Sending toot failed! %s" % e, exc_info=True) def send_email(self, value): - subject = ( - standard_open_message - if value - else standard_close_message - ) + subject = standard_open_message if value else standard_close_message try: post_email(message) except Exception as e: