diff options
| author | Dennis Fink | 2026-10-25 20:47:14 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-25 20:47:14 +0100 |
| commit | a231913ab273f427697f2d27d615b495f6e160bb (patch) | |
| tree | b9d84e3aab3555ec88c648f790f9c31d8a4266a6 /webmentions_ssg/tasks/notifications.py | |
| parent | ae25061b14f8ea713ec7695848421edf84e4f0fc (diff) | |
| download | webmentions-ssg-a231913ab273f427697f2d27d615b495f6e160bb.tar.gz webmentions-ssg-a231913ab273f427697f2d27d615b495f6e160bb.zip | |
feat(receiver): add email notifications for new webmentions
Send an email after a newly received Webmention is successfully
verified, with SMTP delivery configurable through Flask-Mail.
Avoid notifications for resubmissions and manual reverification, and
keep the persisted verification result unchanged if notification
enqueueing fails.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/tasks/notifications.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/webmentions_ssg/tasks/notifications.py b/webmentions_ssg/tasks/notifications.py new file mode 100644 index 0000000..473216b --- /dev/null +++ b/webmentions_ssg/tasks/notifications.py @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me> +# +# SPDX-License-Identifier: BSD-3-Clause + +import uuid + +from flask import current_app +from flask_mail import Message + +from .. import DATABASE as db +from .. import HUEY as huey +from .. import MAIL as mail +from ..models import ReceivedWebmention + + +@huey.task(retries=2, retry_delay=60) +def send_webmention_notification(webmention_uuid: uuid.UUID) -> None: + """Send an email when a received webmention has been verified.""" + recipient = current_app.config.get("WEBMENTIONS_SSG_NOTIFICATION_EMAIL") + if not recipient: + return + + webmention = db.session.get(ReceivedWebmention, webmention_uuid) + if webmention is None or webmention.status != "verified": + return + + message = Message( + subject="New verified webmention", + recipients=[recipient], + body=( + "A received webmention has been verified.\n\n" + f"Source: {webmention.source}\n" + f"Target: {webmention.target}\n" + ), + ) + mail.send(message) |
