alert user when spf fails

This commit is contained in:
Son NK 2020-05-09 23:00:30 +02:00
parent ac4e1fab77
commit 178515dbde
3 changed files with 30 additions and 3 deletions

View File

@ -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 >>>>

View File

@ -108,9 +108,9 @@
<hr>
<h2 class="h4">Advanced Options</h2>
{% if spf_available %}
<div class="card">
<div class="card" id="spf">
<form method="post">
<input type="hidden" name="form-name" value="force-spf">

View File

@ -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: