Add blocked_recipients per account to prevent sending to specific addresses

This commit is contained in:
Kacper Kwapisz
2026-03-23 08:52:59 +01:00
parent 0323eb1f7f
commit 518aeda901
2 changed files with 18 additions and 1 deletions
+5 -1
View File
@@ -21,7 +21,7 @@ accounts:
watch_folders: watch_folders:
- INBOX - INBOX
# Full — separate SMTP settings (only if different from IMAP) # Full — separate SMTP settings, send restrictions
# - id: work # - id: work
# imap_host: imap.example.com # imap_host: imap.example.com
# imap_port: 993 # imap_port: 993
@@ -31,5 +31,9 @@ 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"
# allow_send: true
# blocked_recipients: # agent cannot send to these addresses
# - "ceo@company.com"
# - "all-staff@company.com"
# watch_folders: # watch_folders:
# - INBOX # - INBOX
+13
View File
@@ -608,6 +608,19 @@ async def send_email(
"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."
} }
blocked = {addr.lower() for addr in acc.get("blocked_recipients", [])}
if blocked:
all_recipients = [a.strip().lower() for a in to.split(",")]
if cc:
all_recipients.extend(a.strip().lower() for a in cc.split(","))
if bcc:
all_recipients.extend(a.strip().lower() for a in bcc.split(","))
denied = [r for r in all_recipients if r in blocked]
if denied:
return {
"error": f"Sending to {', '.join(denied)} is blocked. Use create_draft instead."
}
def _send(): def _send():
msg = MIMEMultipart("alternative") if html else MIMEText(body) msg = MIMEMultipart("alternative") if html else MIMEText(body)
if html: if html: