aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/cli/mail.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-27 16:33:56 +0100
committerDennis Fink2026-10-27 16:33:56 +0100
commit5afb245d13b91047d68d7b7343245c41b6460953 (patch)
tree5565d4d42335b4c7c1ef82e2937a50c232c17d47 /webmentions_ssg/cli/mail.py
parenta67967275d0093f0ac3c3af85bf5396511c64422 (diff)
downloadwebmentions-ssg-5afb245d13b91047d68d7b7343245c41b6460953.tar.gz
webmentions-ssg-5afb245d13b91047d68d7b7343245c41b6460953.zip
feat(core): expand user management CLI
Add commands to list users, reset passwords, and delete accounts. Move mail and user commands into dedicated CLI modules.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/cli/mail.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/webmentions_ssg/cli/mail.py b/webmentions_ssg/cli/mail.py
new file mode 100644
index 0000000..07dc50b
--- /dev/null
+++ b/webmentions_ssg/cli/mail.py
@@ -0,0 +1,47 @@
+import click
+from flask import current_app
+from flask.cli import AppGroup
+from flask_mail import Message
+
+from .. import MAIL
+
+MAIL_CLI = AppGroup("mail", help="Handle mail")
+
+
+@MAIL_CLI.command("test", help="Send an email to test the SMTP configuration")
+@click.option(
+ "--to", "recipient", help="Recipient address (defaults to NOTIFICATION_EMAIL)."
+)
+def send_test_mail(recipient: str | None) -> None:
+ """
+ Send a test email using the configured SMTP server.
+
+ :param recipient: Optional recipient overriding NOTIFICATION_EMAIL.
+ :raises click.ClickException: If configuration is missing or sending fails.
+ """
+ recipient = recipient or current_app.config.get("NOTIFICATION_EMAIL")
+ if not recipient:
+ raise click.ClickException(
+ "No recipient specified. Set NOTIFICATION_EMAIL or pass --to."
+ )
+
+ sender = current_app.config.get("MAIL_DEFAULT_SENDER")
+ if not sender:
+ raise click.ClickException("MAIL_DEFAULT_SENDER is not configured.")
+
+ message = Message(
+ subject="webmentions-ssg: test email",
+ sender=sender,
+ recipients=[recipient],
+ body=(
+ "This is a test email from webmentions-ssg.\n\n"
+ "If you received this message, the outgoing mail configuration works.\n"
+ ),
+ )
+
+ try:
+ MAIL.send(message)
+ except Exception as exc:
+ raise click.ClickException(f"Could not send test email: {exc}") from exc
+
+ click.echo(f"Test email sent to {recipient}.")