From 85bb30abb0cb355e1ac0e25a4d37e33086a92365 Mon Sep 17 00:00:00 2001
From: Son NK <>
Date: Sat, 20 Jun 2020 16:19:01 +0200
Subject: [PATCH] Notify user can reply cannot be sent
---
email_handler.py | 39 ++++++++++++++-----
.../emails/transactional/reply-error.html | 30 ++++++++++++++
.../emails/transactional/reply-error.txt | 14 +++++++
3 files changed, 74 insertions(+), 9 deletions(-)
create mode 100644 templates/emails/transactional/reply-error.html
create mode 100644 templates/emails/transactional/reply-error.txt
diff --git a/email_handler.py b/email_handler.py
index 4dc4c056..0973b14c 100644
--- a/email_handler.py
+++ b/email_handler.py
@@ -636,17 +636,38 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, str
# so the client can retry later
return False, "421 SL E13"
- smtp.sendmail(
- alias.email,
- contact.website_email,
- msg.as_bytes(),
- envelope.mail_options,
- envelope.rcpt_options,
- )
+ try:
+ smtp.sendmail(
+ alias.email,
+ contact.website_email,
+ msg.as_bytes(),
+ envelope.mail_options,
+ envelope.rcpt_options,
+ )
+ except Exception:
+ LOG.error("Cannot send email from %s to %s", alias, contact)
+ send_email(
+ mailbox.email,
+ f"Email cannot be sent to {contact.email} from {alias.email}",
+ render(
+ "transactional/reply-error.txt",
+ user=user,
+ alias=alias,
+ contact=contact,
+ contact_domain=get_email_domain_part(contact.email),
+ ),
+ render(
+ "transactional/reply-error.html",
+ user=user,
+ alias=alias,
+ contact=contact,
+ contact_domain=get_email_domain_part(contact.email),
+ ),
+ )
+ else:
+ EmailLog.create(contact_id=contact.id, is_reply=True, user_id=contact.user_id)
- EmailLog.create(contact_id=contact.id, is_reply=True, user_id=contact.user_id)
db.session.commit()
-
return True, "250 Message accepted for delivery"
diff --git a/templates/emails/transactional/reply-error.html b/templates/emails/transactional/reply-error.html
new file mode 100644
index 00000000..7e7440f6
--- /dev/null
+++ b/templates/emails/transactional/reply-error.html
@@ -0,0 +1,30 @@
+{% extends "base.html" %}
+
+{% block content %}
+ {{ render_text("Hi " + (user.name or "")) }}
+
+ {% call text() %}
+ Your email cannot be sent to {{ contact.email }} from your alias {{ alias.email }}.
+ {% endcall %}
+
+ {% call text() %}
+ Can you please verify {{ contact.email }} is a valid address?
+ {% endcall %}
+
+ {% call text() %}
+ Usually this is because the DNS record of {{ contact_domain }} does not exist.
+ {% endcall %}
+
+ {% call text() %}
+ You can check its DNS record on any DNS checker websites, for example https://mxtoolbox.com/SuperTool.aspx
+ {% endcall %}
+
+ {% call text() %}
+ Please let us know if you have any question.
+ Best,
+ SimpleLogin team.
+ {% endcall %}
+
+{% endblock %}
+
+
diff --git a/templates/emails/transactional/reply-error.txt b/templates/emails/transactional/reply-error.txt
new file mode 100644
index 00000000..874e11ae
--- /dev/null
+++ b/templates/emails/transactional/reply-error.txt
@@ -0,0 +1,14 @@
+Hi {{user.name or ""}}
+
+Your email cannot be sent to {{contact.email}} from your alias {{alias.email}}.
+
+Can you please verify {{contact.email}} is a valid address?
+
+Usually this is because the DNS record of {{contact_domain}} does not exist.
+
+You can check its DNS record on any DNS checker websites, for example https://mxtoolbox.com/SuperTool.aspx
+
+Please let us know if you have any question.
+
+Best,
+SimpleLogin team.
\ No newline at end of file