diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2024-03-01 15:00:01 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-12-21 19:43:13 +0200 |
| commit | 6c2c945d192c707293aedba29ac94b8b677f7b3e (patch) | |
| tree | 752e90f05f81aef5cdd971230a026625eb2948ea /email_client.py | |
| parent | f778686fece43cad8c2b08293e505ceeebe1890a (diff) | |
Send emails in a background thread
Diffstat (limited to 'email_client.py')
| -rw-r--r-- | email_client.py | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/email_client.py b/email_client.py index acb6c9c..e06c901 100644 --- a/email_client.py +++ b/email_client.py @@ -67,38 +67,38 @@ if email_enabled: else: print("SMTP email client not enabled") -def send_participation_email_if_enabled(poll_id: str, voter_name: str): - if email_enabled: - poll = db.get_poll(poll_id) - if not poll or poll.author_email is None: - return +def send_participation_email(poll_id: str, voter_name: str): + poll = db.get_poll(poll_id) + if not poll or poll.author_email is None: + return - try: - send_email( - subject=f"{voter_name} participated in your poll \"{poll.title}\"", - body=f"{voter_name} participated in your diddle \"{poll.title}\".\n\n" - f"View the results at {BASE_URL}/poll/{poll.id}\n" - f"Manage your diddle at {BASE_URL}/manage/{poll.manage_code}\n" - "You will be notified by email when someone participates.", - recipient=poll.author_email, - ) - except Exception as e: - traceback.print_exc(file=sys.stderr) - print(f"Failed to send participation email to {poll.author_email}", file=sys.stderr) + print(f"Sending participation email to {poll.author_email}") + try: + send_email( + subject=f"{voter_name} participated in your poll \"{poll.title}\"", + body=f"{voter_name} participated in your diddle \"{poll.title}\".\n\n" + f"View the results at {BASE_URL}/poll/{poll.id}\n" + f"Manage your diddle at {BASE_URL}/manage/{poll.manage_code}\n" + "You will be notified by email when someone participates.", + recipient=poll.author_email, + ) + except Exception as e: + traceback.print_exc(file=sys.stderr) + print(f"Failed to send participation email to {poll.author_email}", file=sys.stderr) -def send_poll_created_email_if_enabled(poll_id: str): - if email_enabled: - poll = db.get_poll(poll_id) - if not poll or poll.author_email is None: - return +def send_poll_created_email(poll_id: str): + poll = db.get_poll(poll_id) + if not poll or poll.author_email is None: + return - try: - send_email( - subject=f"You created a new diddle \"{poll.title}\"", - body=f"Manage your diddle at {BASE_URL}/manage/{poll.manage_code}\n" - "You will be notified by email when someone participates.", - recipient=poll.author_email, - ) - except Exception as e: - traceback.print_exc(file=sys.stderr) - print(f"Failed to send poll created email to {poll.author_email}", file=sys.stderr)
\ No newline at end of file + print(f"Sending poll created email to {poll.author_email}") + try: + send_email( + subject=f"You created a new diddle \"{poll.title}\"", + body=f"Manage your diddle at {BASE_URL}/manage/{poll.manage_code}\n" + "You will be notified by email when someone participates.", + recipient=poll.author_email, + ) + except Exception as e: + traceback.print_exc(file=sys.stderr) + print(f"Failed to send poll created email to {poll.author_email}", file=sys.stderr) |
