diff --git a/src/task_scheduler.py b/src/task_scheduler.py
index 9c7ac754e..c2398647f 100644
--- a/src/task_scheduler.py
+++ b/src/task_scheduler.py
@@ -1712,8 +1712,15 @@ class TaskScheduler:
target = (output or "").strip()
explicit = ""
+ account_id = ""
if target.startswith("email:"):
explicit = target.split(":", 1)[1].strip()
+ if "|account=" in explicit:
+ explicit, account_id = explicit.split("|account=", 1)
+ explicit = explicit.strip()
+ account_id = account_id.strip()
+ if explicit == "self":
+ explicit = ""
elif "@" in target:
explicit = target
@@ -1721,7 +1728,7 @@ class TaskScheduler:
from routes.email_routes import _resolve_send_config
from routes.email_helpers import _send_smtp_message
- cfg = _resolve_send_config(owner=task.owner or "")
+ cfg = _resolve_send_config(account_id=account_id or None, owner=task.owner or "")
to_addr = explicit or cfg.get("from_address") or cfg.get("smtp_user") or ""
if not to_addr:
raise RuntimeError("No email recipient resolved for task output")
diff --git a/static/js/tasks.js b/static/js/tasks.js
index df0f62e4a..c8ae8feb3 100644
--- a/static/js/tasks.js
+++ b/static/js/tasks.js
@@ -254,6 +254,34 @@ function _taskPromptConfig(prompt) {
}
}
+function _parseTaskEmailOutputTarget(output) {
+ const raw = String(output || '').trim();
+ if (!raw) return { enabled: false, to: '', accountId: '' };
+ if (raw === 'email') return { enabled: true, to: '', accountId: '' };
+ if (/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(raw)) return { enabled: true, to: raw, accountId: '' };
+ if (!raw.startsWith('email:')) return { enabled: false, to: '', accountId: '' };
+ let payload = raw.slice('email:'.length).trim();
+ let accountId = '';
+ const marker = '|account=';
+ const markerIdx = payload.indexOf(marker);
+ if (markerIdx >= 0) {
+ accountId = payload.slice(markerIdx + marker.length).trim();
+ payload = payload.slice(0, markerIdx).trim();
+ }
+ return {
+ enabled: true,
+ to: payload && payload !== 'self' ? payload : '',
+ accountId,
+ };
+}
+
+function _buildTaskEmailOutputTarget(to, accountId) {
+ const cleanTo = String(to || '').trim();
+ const cleanAccount = String(accountId || '').trim();
+ const base = `email:${cleanTo || 'self'}`;
+ return cleanAccount ? `${base}|account=${cleanAccount}` : (cleanTo ? base : 'email');
+}
+
async function _renderEmailActionOptions(action, existing, extra) {
if (!_EMAIL_ACCOUNT_ACTIONS.has(action)) return;
const accounts = (await _fetchEmailAccountsForTasks()).filter(a => a && a.enabled !== false);
@@ -1141,6 +1169,7 @@ function _showForm(existing, initTaskType, initTriggerType) {
+