Report error when SPF fails on emails sent from mailbox. Return 451 instead of 550 to avoid bounce emails.

This commit is contained in:
Son NK 2020-05-09 14:52:39 +02:00
parent a3a8a13840
commit 5ec0ea5f6c
1 changed files with 6 additions and 3 deletions

View File

@ -477,10 +477,13 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, str
# TODO: Handle temperr case (e.g. dns timeout)
# only an absolute pass, or no SPF policy at all is 'valid'
if r[0] not in ["pass", "none"]:
LOG.d(
"SPF validation failed for %s (reason %s)", mailbox_email, r[0],
LOG.error(
"SPF fail for mailbox %s, reason %s, failed IP %s",
mailbox_email,
r[0],
msg["X-SimpleLogin-Client-IP"],
)
return False, "550 SL E11"
return False, "451 SL E11"
else:
LOG.d(
"Could not find X-SimpleLogin-Client-IP header %s -> %s",