Skip to content

Automate browser based workflows with AI

Stop appending the run ID to Send Email subjects (SKY-16062) (#8527)

Aaron Perezf748fcc3bbe0
diff --git a/docs/cloud/building-agents/configure-blocks.mdx b/docs/cloud/building-agents/configure-blocks.mdx
index b66ab30fa..f9f84273d 100644
--- a/docs/cloud/building-agents/configure-blocks.mdx
+++ b/docs/cloud/building-agents/configure-blocks.mdx
@@ -427,7 +427,7 @@ Send an email notification, optionally with file attachments from previous block
| Field | Type | Description |
|-------|------|-------------|
| **Recipients** | text | Comma-separated email addresses |
-| **Subject** | text | Email subject line |
+| **Subject** | text | Email subject line. Supports [parameter references](/cloud/building-agents/add-parameters#referencing-parameters-in-blocks) — add `{{workflow_run_id}}` to tag the subject with the run, e.g. `Your Run is Finished {{workflow_run_id}}`. |
| **Body** | text | Email body. Supports [parameter references](/cloud/building-agents/add-parameters#referencing-parameters-in-blocks). |
| **Body format** | select | `Text` (default) sends the body exactly as written. `HTML` renders the body as a formatted email and adds a plain-text version for clients that cannot show HTML; `<script>`, `<iframe>`, `<object>`, `<embed>`, `<svg>`, `<math>`, meta refresh directives, event-handler attributes and links whose scheme is not `http`, `https`, `mailto`, `tel` or `cid` (inline `data:image` sources are kept) are removed before sending. Mail clients strip inline SVG anyway, so use a raster image instead. `{{ }}` and `{% %}` are parameter syntax, so wrap literal braces in `{% raw %}…{% endraw %}`. |
| **File Attachments** | text | Path to files to attach |
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/SendEmailNode/SendEmailEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/SendEmailNode/SendEmailEditor.tsx
index d9cf165b9..658d5bb66 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/SendEmailNode/SendEmailEditor.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/SendEmailNode/SendEmailEditor.tsx
@@ -78,7 +78,7 @@ function SendEmailEditorBody({
nodeId={blockId}
onChange={(value) => update({ subject: value })}
value={subject}
- placeholder="What is the gist?"
+ placeholder="Your Run is Finished {{workflow_run_id}}"
className="nopan text-xs"
/>
</div>
diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/SendEmailBlockForm.test.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/SendEmailBlockForm.test.tsx
index 3cc98f24e..533b9c903 100644
--- a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/SendEmailBlockForm.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/SendEmailBlockForm.test.tsx
@@ -165,7 +165,9 @@ describe("SendEmailBlockForm (SKY-9379)", () => {
expect(
screen.getByPlaceholderText("[email protected], [email protected]..."),
).toBeDefined();
- expect(screen.getByPlaceholderText("What is the gist?")).toBeDefined();
+ expect(
+ screen.getByPlaceholderText("Your Run is Finished {{workflow_run_id}}"),
+ ).toBeDefined();
expect(
screen.getByPlaceholderText("What would you like to say?"),
).toBeDefined();
@@ -220,7 +222,7 @@ describe("SendEmailBlockForm (SKY-9379)", () => {
render(<SendEmailBlockForm blockId="b1" />);
const input = screen.getByPlaceholderText(
- "What is the gist?",
+ "Your Run is Finished {{workflow_run_id}}",
) as HTMLInputElement;
fireEvent.change(input, { target: { value: "new subject" } });
@@ -262,7 +264,7 @@ describe("SendEmailBlockForm (SKY-9379)", () => {
render(<SendEmailBlockForm blockId="b1" />);
const input = screen.getByPlaceholderText(
- "What is the gist?",
+ "Your Run is Finished {{workflow_run_id}}",
) as HTMLInputElement;
fireEvent.change(input, { target: { value: "subject change" } });
diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.py
index cec9d4cd1..1ea57f02a 100644
--- a/skyvern/forge/sdk/workflow/models/block.py
+++ b/skyvern/forge/sdk/workflow/models/block.py
@@ -11143,9 +11143,9 @@ class SendEmailBlock(Block):
organization_id: str | None = None,
) -> EmailMessage:
msg = EmailMessage()
- msg["Subject"] = (
- self.subject.strip().replace("\n", "").replace("\r", "") + f" - Workflow Run ID: {workflow_run_id}"
- )
+ # Flattened after Jinja rendering: a substituted value carrying a newline would otherwise
+ # be rejected by the email header policy and fail the send.
+ msg["Subject"] = self.subject.strip().replace("\n", "").replace("\r", "")
msg["To"] = ", ".join(self.get_real_email_recipients(workflow_run_context))
msg["BCC"] = self.sender # BCC the sender so there is a record of the email being sent
msg["From"] = self.sender
diff --git a/tests/unit/test_send_email_block.py b/tests/unit/test_send_email_block.py
index 8b3ed64b2..11bb11c79 100644
--- a/tests/unit/test_send_email_block.py
+++ b/tests/unit/test_send_email_block.py
@@ -11,6 +11,8 @@
blocks deliver to every address, and an invalid one fails the block without being echoed.
- SKY-15919: `body_format: html` on either block sends a multipart/alternative message (generated
plain-text part + sanitized HTML part); the default `text` path is byte-identical to before.
+- SKY-16062: the subject is exactly what the user wrote — no run id is appended. Users who
+ want it place {{workflow_run_id}} themselves.
"""
from __future__ import annotations
@@ -1102,3 +1104,37 @@ def test_generated_script_emits_body_format_only_when_html() -> None:
assert "body_format" not in compact(_send_email_block().model_dump())
legacy_block = {"label": "notify", "sender": "[email protected]", "recipients": [], "subject": "s", "body": "b"}
assert "body_format" not in compact(legacy_block)
+
+
+async def test_subject_carries_only_what_the_user_wrote(offline_address_validation: None) -> None:
+ context = _workflow_run_context({})
+
+ block = _send_email_block(subject=" Your order shipped ")
+ block.format_potential_template_parameters(context)
+
+ assert (await block._build_email_message(context, "wr_1"))["Subject"] == "Your order shipped"
+
+
+async def test_subject_renders_the_run_id_where_the_user_placed_it(offline_address_validation: None) -> None:
+ context = _workflow_run_context({})
+
+ block = _send_email_block(subject="Your Run is Finished {{workflow_run_id}}")
+ block.format_potential_template_parameters(context)
+
+ assert (await block._build_email_message(context, "wr_1"))["Subject"] == "Your Run is Finished wr_1"
+
+
+async def test_a_substituted_newline_is_flattened_rather_than_failing_the_send(
+ offline_address_validation: None,
+) -> None:
+ context = _workflow_run_context({"injected": "ok\r\nBcc: [email protected]"})
+
+ block = _send_email_block(subject="Report {{injected}}")
+ block.format_potential_template_parameters(context)
+ message = await block._build_email_message(context, "wr_1")
+
+ assert message["Subject"] == "Report okBcc: [email protected]"
+ assert message["BCC"] == "[email protected]"