diff --git a/app/email_utils.py b/app/email_utils.py
index ba2b7acc..9d6926b2 100644
--- a/app/email_utils.py
+++ b/app/email_utils.py
@@ -193,7 +193,7 @@ def send_cannot_create_domain_alias(user, alias, domain):
def send_email(to_email, subject, plaintext, html=None):
if NOT_SEND_EMAIL:
LOG.d(
- "send email with subject %s to %s, plaintext: %s",
+ "send email with subject '%s' to '%s', plaintext: %s",
subject,
to_email,
plaintext,
diff --git a/cron.py b/cron.py
index 5765a330..3ed12027 100644
--- a/cron.py
+++ b/cron.py
@@ -12,7 +12,10 @@ from app.config import (
ADMIN_EMAIL,
MACAPP_APPLE_API_SECRET,
APPLE_API_SECRET,
+ EMAIL_SERVERS_WITH_PRIORITY,
+ URL,
)
+from app.dns_utils import get_mx_domains
from app.email_utils import (
send_email,
send_trial_end_soon_email,
@@ -314,6 +317,41 @@ def sanity_check():
LOG.d("Finish sanity check")
+def check_custom_domain():
+ LOG.d("Check verified domain for DNS issues")
+
+ for custom_domain in CustomDomain.query.filter(CustomDomain.verified == True):
+ mx_domains = get_mx_domains(custom_domain.domain)
+
+ if sorted(mx_domains) != sorted(EMAIL_SERVERS_WITH_PRIORITY):
+ user = custom_domain.user
+ LOG.exception(
+ "The MX record is not correctly set for %s %s %s",
+ custom_domain,
+ user,
+ mx_domains,
+ )
+
+ domain_dns_url = f"{URL}/dashboard/domains/{custom_domain.id}/dns"
+
+ send_email(
+ user.email,
+ f"Please update {custom_domain.domain} DNS on SimpleLogin",
+ render(
+ "transactional/custom-domain-dns-issue.txt",
+ custom_domain=custom_domain,
+ name=user.name or "",
+ domain_dns_url=domain_dns_url,
+ ),
+ render(
+ "transactional/custom-domain-dns-issue.html",
+ custom_domain=custom_domain,
+ name=user.name or "",
+ domain_dns_url=domain_dns_url,
+ ),
+ )
+
+
def delete_old_monitoring():
"""
Delete old monitoring records
@@ -341,6 +379,7 @@ if __name__ == "__main__":
"poll_apple_subscription",
"sanity_check",
"delete_old_monitoring",
+ "check_custom_domain",
],
)
args = parser.parse_args()
@@ -372,3 +411,6 @@ if __name__ == "__main__":
elif args.job == "delete_old_monitoring":
LOG.d("Delete old monitoring records")
delete_old_monitoring()
+ elif args.job == "check_custom_domain":
+ LOG.d("Check custom domain")
+ check_custom_domain()
diff --git a/crontab.yml b/crontab.yml
index f2461814..b5f6eb54 100644
--- a/crontab.yml
+++ b/crontab.yml
@@ -47,3 +47,8 @@ jobs:
schedule: "0 14 * * *"
captureStderr: true
+ - name: SimpleLogin Custom Domain check
+ command: python /code/cron.py -j check_custom_domain
+ shell: /bin/bash
+ schedule: "0 15 * * *"
+ captureStderr: true
diff --git a/templates/emails/transactional/custom-domain-dns-issue.html b/templates/emails/transactional/custom-domain-dns-issue.html
new file mode 100644
index 00000000..dea74d34
--- /dev/null
+++ b/templates/emails/transactional/custom-domain-dns-issue.html
@@ -0,0 +1,23 @@
+{% extends "base.html" %}
+
+{% block content %}
+ {{ render_text("Hi " + name) }}
+
+ {% call text() %}
+ We have detected that your domain {{ custom_domain.domain }} does not have the DNS set up correctly.
+ {% endcall %}
+
+ {% call text() %}
+ Please make sure to set up your domain following the instructions on your domain DNS page at
+ {{ custom_domain.domain }} DNS.
+ {% endcall %}
+
+ {% call text() %}
+ Feel free reply to this email if you have any question.
+ Best,
+ SimpleLogin team.
+ {% endcall %}
+
+{% endblock %}
+
+
diff --git a/templates/emails/transactional/custom-domain-dns-issue.txt b/templates/emails/transactional/custom-domain-dns-issue.txt
new file mode 100644
index 00000000..6379a302
--- /dev/null
+++ b/templates/emails/transactional/custom-domain-dns-issue.txt
@@ -0,0 +1,11 @@
+Hi {{name}}
+
+We have detected that your domain {{ custom_domain.domain }} does not have the DNS set up correctly.
+
+Please make sure to set up your domain following the instructions on your domain DNS page at:
+{{ domain_dns_url }}
+
+Feel free reply to this email if you have any question.
+
+Best,
+SimpleLogin team.
\ No newline at end of file