diff --git a/config.example.yml b/config.example.yml index 8edf387..0c767f0 100644 --- a/config.example.yml +++ b/config.example.yml @@ -7,9 +7,9 @@ poke_api_key: "your-api-key-here" # MCP_API_KEY is set via environment variable (not in this file) # It secures the MCP server so only you can use it -# Global send toggle — disabled by default for safety. -# Agents can still use create_draft. Enable per account with allow_send: true -allow_send: false +# Global send toggle — set to false to disable send_email for all accounts +# Agents can still use create_draft. Override per account with allow_send. +allow_send: true accounts: # Minimal — SMTP falls back to IMAP host/credentials @@ -31,5 +31,6 @@ accounts: # smtp_port: 587 # smtp_username: "you@example.com" # 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: # - INBOX diff --git a/src/server.py b/src/server.py index 9afac01..5529333 100755 --- a/src/server.py +++ b/src/server.py @@ -82,11 +82,15 @@ def parse_accounts(config: dict) -> list[dict]: "smtp_password": os.environ.get( "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"], } ] - global_allow_send = config.get("allow_send", False) + global_allow_send = config.get("allow_send", True) required = ("imap_host", "imap_username", "imap_password") for i, acc in enumerate(accounts): 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_username", acc.get("imap_username")) acc.setdefault("smtp_password", acc.get("imap_password")) + acc.setdefault("from_address", acc.get("smtp_username")) acc.setdefault("allow_send", global_allow_send) for field in required: if field not in acc: @@ -603,7 +608,7 @@ async def send_email( accounts = ctx.lifespan_context["accounts"] acc = resolve_account(accounts, account_id) - if not acc.get("allow_send", False): + if not acc.get("allow_send", True): return { "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(html, "html")) - msg["From"] = acc["smtp_username"] + msg["From"] = acc["from_address"] msg["To"] = to msg["Subject"] = subject if cc: @@ -689,7 +694,7 @@ async def create_draft( msg.attach(MIMEText(body, "plain")) msg.attach(MIMEText(html, "html")) - msg["From"] = acc["smtp_username"] + msg["From"] = acc["from_address"] msg["To"] = to msg["Subject"] = subject if cc: