From 15ce7b00d89d2c4e4214fafd874f9742b365d4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Wed, 16 Feb 2022 18:38:31 +0100 Subject: [PATCH] Reply to noreply@... once per user --- app/config.py | 2 ++ email_handler.py | 18 ++++++++++++++++-- .../emails/transactional/noreply.text.jinja2 | 7 +++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 templates/emails/transactional/noreply.text.jinja2 diff --git a/app/config.py b/app/config.py index 1f6d0b15..44c93a71 100644 --- a/app/config.py +++ b/app/config.py @@ -318,6 +318,8 @@ ALERT_NON_REVERSE_ALIAS_REPLY_PHASE = "non_reverse_alias_reply_phase" ALERT_FROM_ADDRESS_IS_REVERSE_ALIAS = "from_address_is_reverse_alias" +ALERT_TO_NOREPLY = "to_noreply" + ALERT_SPF = "spf" ALERT_INVALID_TOTP_LOGIN = "invalid_totp_login" diff --git a/email_handler.py b/email_handler.py index 61f503f3..d4ddf986 100644 --- a/email_handler.py +++ b/email_handler.py @@ -86,6 +86,7 @@ from app.config import ( ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE, OLD_UNSUBSCRIBER, ALERT_FROM_ADDRESS_IS_REVERSE_ALIAS, + ALERT_TO_NOREPLY, ) from app.db import Session from app.email import status, headers @@ -2078,6 +2079,18 @@ def should_ignore(mail_from: str, rcpt_tos: List[str]) -> bool: return False +def send_no_reply_response(mail_from: str, msg: Message): + user = User.get_by(email=mail_from) + if user: + send_email_at_most_times( + user, + ALERT_TO_NOREPLY, + user.email, + "Auto: {}".format(msg[headers.SUBJECT] or "No subject"), + render("transactional/noreply.text.jinja2"), + ) + + def handle(envelope: Envelope, msg: Message) -> str: """Return SMTP status""" @@ -2300,8 +2313,9 @@ def handle(envelope: Envelope, msg: Message) -> str: nb_rcpt_tos = len(rcpt_tos) for rcpt_index, rcpt_to in enumerate(rcpt_tos): if rcpt_to == NOREPLY: - LOG.e("email sent to noreply address from %s", mail_from) - return status.E514 + LOG.i("email sent to {} address from {}".format(NOREPLY, mail_from)) + send_no_reply_response(mail_from, msg) + return status.E200 # create a copy of msg for each recipient except the last one # as copy() is a slow function diff --git a/templates/emails/transactional/noreply.text.jinja2 b/templates/emails/transactional/noreply.text.jinja2 new file mode 100644 index 00000000..c863e001 --- /dev/null +++ b/templates/emails/transactional/noreply.text.jinja2 @@ -0,0 +1,7 @@ +Hi! + + Thanks for getting in touch. This mailbox cannot receive any emails. If you need help, please go to https://app.simplelogin.io/dashboard/support to contact us. + +Best! + + SimpleLogin team