You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sb...@apache.org on 2026/08/27 15:17:41 UTC
(tooling-trusted-releases) 01/01: Add an admin page to test sending email
This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch sbp
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
commit c368d1a5b51d952331a52bfc9750123e8375f703
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Thu Aug 27 16:17:13 2026 +0100
Add an admin page to test sending email
---
atr/admin/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++
atr/templates/includes/topnav.html | 5 +++++
2 files changed, 48 insertions(+)
diff --git a/atr/admin/__init__.py b/atr/admin/__init__.py
index 30e0b0c9..47429a82 100644
--- a/atr/admin/__init__.py
+++ b/atr/admin/__init__.py
@@ -55,6 +55,7 @@ import atr.htm as htm
import atr.jwtoken as jwtoken
import atr.ldap as ldap
import atr.log as log
+import atr.mail as mail
import atr.mapping as mapping
import atr.models.api as api
import atr.models.safe as safe
@@ -2477,6 +2478,48 @@ async def tasks_recent(_session: web.Committer, _tasks_recent: Literal["tasks/re
return await template.blank(f"Recent Tasks ({minutes}m)", content=page.collect())
+@admin.typed
+async def test_message_get(session: web.Committer, _test_message: Literal["test-message"]) -> str:
+ rendered_form = await form.render(
+ model_cls=form.Empty,
+ submit_label="Send test message",
+ )
+ page = htm.Block()
+ page.h1["Send a test message"]
+ page.p[
+ "Send a test email to ",
+ htpy.code["dev@tooling.apache.org"],
+ " from ",
+ htpy.code[f"{session.asf_uid}@apache.org"],
+ " to check that outbound mail works.",
+ ]
+ page.append(rendered_form)
+ return await template.blank(title="Send a test message", content=page.collect())
+
+
+@admin.typed
+async def test_message_post(
+ session: web.Committer, _test_message: Literal["test-message"], _send_form: form.Empty
+) -> web.WerkzeugResponse:
+ timestamp = util.format_datetime(datetime.datetime.now(datetime.UTC))
+ message = mail.Message(
+ email_sender=f"{session.asf_uid}@apache.org",
+ email_to="dev@tooling.apache.org",
+ subject="Test message",
+ body=f"Test sent by {session.asf_uid} at {timestamp}.",
+ )
+ async with storage.write(session) as write:
+ wafc = write.as_foundation_committer()
+ mid, errors = await wafc.mail.send(message, mail.MailFooterCategory.NONE)
+ if errors:
+ await quart.flash(f"Sending failed: {'; '.join(errors)}", "error")
+ elif config.is_dev_environment():
+ await quart.flash("Dev environment, so the message was logged to sent-email-dev.log and not sent.", "success")
+ else:
+ await quart.flash(f"Sent test message {mid} to dev@tooling.apache.org.", "success")
+ return await session.redirect(test_message_get)
+
+
@admin.typed
async def test_roster_get(_session: web.Committer, _test_roster: Literal["test-roster"]) -> str:
"""
diff --git a/atr/templates/includes/topnav.html b/atr/templates/includes/topnav.html
index 450758a8..07697c7f 100644
--- a/atr/templates/includes/topnav.html
+++ b/atr/templates/includes/topnav.html
@@ -332,6 +332,11 @@
<a class="dropdown-item"
href="{{ as_url(admin.tasks_recent, minutes=5) }}"><i class="bi bi-list-task"></i> Recent tasks</a>
</li>
+ <li>
+ <a class="dropdown-item"
+ href="{{ as_url(admin.test_message_get) }}"
+ {% if request.endpoint == 'atr_admin_test_message_get' %}class="active"{% endif %}><i class="bi bi-envelope"></i> Send test message</a>
+ </li>
<li>
<a class="dropdown-item"
href="{{ as_url(admin.validate_) }}"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org