Add from_address override per account for custom domain sending
Useful for iCloud SMTP where login is @icloud.com but you send as a custom domain. Falls back to smtp_username when not set.
This commit is contained in:
+4
-3
@@ -7,9 +7,9 @@ poke_api_key: "your-api-key-here"
|
|||||||
# MCP_API_KEY is set via environment variable (not in this file)
|
# MCP_API_KEY is set via environment variable (not in this file)
|
||||||
# It secures the MCP server so only you can use it
|
# It secures the MCP server so only you can use it
|
||||||
|
|
||||||
# Global send toggle — disabled by default for safety.
|
# Global send toggle — set to false to disable send_email for all accounts
|
||||||
# Agents can still use create_draft. Enable per account with allow_send: true
|
# Agents can still use create_draft. Override per account with allow_send.
|
||||||
allow_send: false
|
allow_send: true
|
||||||
|
|
||||||
accounts:
|
accounts:
|
||||||
# Minimal — SMTP falls back to IMAP host/credentials
|
# Minimal — SMTP falls back to IMAP host/credentials
|
||||||
@@ -31,5 +31,6 @@ accounts:
|
|||||||
# smtp_port: 587
|
# smtp_port: 587
|
||||||
# smtp_username: "you@example.com"
|
# smtp_username: "you@example.com"
|
||||||
# smtp_password: "smtp-password"
|
# smtp_password: "smtp-password"
|
||||||
|
# from_address: "you@customdomain.com" # Override From: header (e.g. iCloud login is @icloud.com but you send as custom domain)
|
||||||
# watch_folders:
|
# watch_folders:
|
||||||
# - INBOX
|
# - INBOX
|
||||||
|
|||||||
+9
-4
@@ -82,11 +82,15 @@ def parse_accounts(config: dict) -> list[dict]:
|
|||||||
"smtp_password": os.environ.get(
|
"smtp_password": os.environ.get(
|
||||||
"SMTP_PASSWORD", os.environ["IMAP_PASSWORD"]
|
"SMTP_PASSWORD", os.environ["IMAP_PASSWORD"]
|
||||||
),
|
),
|
||||||
|
"from_address": os.environ.get(
|
||||||
|
"FROM_ADDRESS",
|
||||||
|
os.environ.get("SMTP_USERNAME", os.environ["IMAP_USERNAME"]),
|
||||||
|
),
|
||||||
"watch_folders": ["INBOX"],
|
"watch_folders": ["INBOX"],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
global_allow_send = config.get("allow_send", False)
|
global_allow_send = config.get("allow_send", True)
|
||||||
required = ("imap_host", "imap_username", "imap_password")
|
required = ("imap_host", "imap_username", "imap_password")
|
||||||
for i, acc in enumerate(accounts):
|
for i, acc in enumerate(accounts):
|
||||||
acc.setdefault("id", f"account-{i}")
|
acc.setdefault("id", f"account-{i}")
|
||||||
@@ -97,6 +101,7 @@ def parse_accounts(config: dict) -> list[dict]:
|
|||||||
acc.setdefault("smtp_port", 587)
|
acc.setdefault("smtp_port", 587)
|
||||||
acc.setdefault("smtp_username", acc.get("imap_username"))
|
acc.setdefault("smtp_username", acc.get("imap_username"))
|
||||||
acc.setdefault("smtp_password", acc.get("imap_password"))
|
acc.setdefault("smtp_password", acc.get("imap_password"))
|
||||||
|
acc.setdefault("from_address", acc.get("smtp_username"))
|
||||||
acc.setdefault("allow_send", global_allow_send)
|
acc.setdefault("allow_send", global_allow_send)
|
||||||
for field in required:
|
for field in required:
|
||||||
if field not in acc:
|
if field not in acc:
|
||||||
@@ -603,7 +608,7 @@ async def send_email(
|
|||||||
accounts = ctx.lifespan_context["accounts"]
|
accounts = ctx.lifespan_context["accounts"]
|
||||||
acc = resolve_account(accounts, account_id)
|
acc = resolve_account(accounts, account_id)
|
||||||
|
|
||||||
if not acc.get("allow_send", False):
|
if not acc.get("allow_send", True):
|
||||||
return {
|
return {
|
||||||
"error": f"Sending is disabled for account '{acc['id']}'. Use create_draft instead."
|
"error": f"Sending is disabled for account '{acc['id']}'. Use create_draft instead."
|
||||||
}
|
}
|
||||||
@@ -614,7 +619,7 @@ async def send_email(
|
|||||||
msg.attach(MIMEText(body, "plain"))
|
msg.attach(MIMEText(body, "plain"))
|
||||||
msg.attach(MIMEText(html, "html"))
|
msg.attach(MIMEText(html, "html"))
|
||||||
|
|
||||||
msg["From"] = acc["smtp_username"]
|
msg["From"] = acc["from_address"]
|
||||||
msg["To"] = to
|
msg["To"] = to
|
||||||
msg["Subject"] = subject
|
msg["Subject"] = subject
|
||||||
if cc:
|
if cc:
|
||||||
@@ -689,7 +694,7 @@ async def create_draft(
|
|||||||
msg.attach(MIMEText(body, "plain"))
|
msg.attach(MIMEText(body, "plain"))
|
||||||
msg.attach(MIMEText(html, "html"))
|
msg.attach(MIMEText(html, "html"))
|
||||||
|
|
||||||
msg["From"] = acc["smtp_username"]
|
msg["From"] = acc["from_address"]
|
||||||
msg["To"] = to
|
msg["To"] = to
|
||||||
msg["Subject"] = subject
|
msg["Subject"] = subject
|
||||||
if cc:
|
if cc:
|
||||||
|
|||||||
Reference in New Issue
Block a user