diff --git a/app/config.py b/app/config.py index 05bb7f46..6f35484d 100644 --- a/app/config.py +++ b/app/config.py @@ -255,6 +255,8 @@ APPLE_API_SECRET = os.environ.get("APPLE_API_SECRET") # for Mac App MACAPP_APPLE_API_SECRET = os.environ.get("MACAPP_APPLE_API_SECRET") +# <<<<< ALERT EMAIL >>>> + # maximal number of alerts that can be sent to the same email in 24h MAX_ALERT_24H = 4 @@ -266,3 +268,7 @@ ALERT_BOUNCE_EMAIL = "bounce" # When a forwarding email is detected as spam ALERT_SPAM_EMAIL = "spam" + +ALERT_SPF = "spf" + +# <<<<< END ALERT EMAIL >>>> diff --git a/app/dashboard/templates/dashboard/mailbox_detail.html b/app/dashboard/templates/dashboard/mailbox_detail.html index b2fb0ce6..816b1ca8 100644 --- a/app/dashboard/templates/dashboard/mailbox_detail.html +++ b/app/dashboard/templates/dashboard/mailbox_detail.html @@ -108,9 +108,9 @@

Advanced Options

- + {% if spf_available %} -
+
diff --git a/email_handler.py b/email_handler.py index bbb31894..5f1d9f32 100644 --- a/email_handler.py +++ b/email_handler.py @@ -59,6 +59,7 @@ from app.config import ( ALERT_REVERSE_ALIAS_UNKNOWN_MAILBOX, ALERT_BOUNCE_EMAIL, ALERT_SPAM_EMAIL, + ALERT_SPF, ) from app.email_utils import ( send_email, @@ -493,7 +494,27 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, str "SPF fail for mailbox %s, reason %s, failed IP %s", mailbox_email, r[0], - msg[_IP_HEADER], + ip, + ) + send_email_with_rate_control( + user, + ALERT_SPF, + mailbox_email, + f"SimpleLogin Alert: attempt to send emails from your alias {alias.email} from unknown IP Address", + render( + "transactional/spf-fail.txt", + name=user.name, + alias=alias.email, + ip=ip, + mailbox_url=URL + f"/dashboard/mailbox/{mailb.id}#spf", + ), + render( + "transactional/spf-fail.html", + name=user.name, + alias=alias.email, + ip=ip, + mailbox_url=URL + f"/dashboard/mailbox/{mailb.id}#spf", + ), ) return False, "451 SL E11" else: