瀏覽代碼

Notify user can reply cannot be sent

Son NK 5 年之前
父節點
當前提交
85bb30abb0
共有 3 個文件被更改,包括 74 次插入9 次删除
  1. 30 9
      email_handler.py
  2. 30 0
      templates/emails/transactional/reply-error.html
  3. 14 0
      templates/emails/transactional/reply-error.txt

+ 30 - 9
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"
 
 

+ 30 - 0
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 <b>{{ contact.email }}</b> from your alias <b>{{ alias.email }}</b>.
+  {% endcall %}
+
+  {% call text() %}
+    Can you please verify <b>{{ contact.email }}</b> is a valid address?
+  {% endcall %}
+
+  {% call text() %}
+    Usually this is because the DNS record of <b>{{ contact_domain }}</b> 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. <br>
+    Best, <br>
+    SimpleLogin team.
+  {% endcall %}
+
+{% endblock %}
+
+

+ 14 - 0
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.