diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py
index 85cb1ed1..62796b72 100644
--- a/core/admin/mailu/models.py
+++ b/core/admin/mailu/models.py
@@ -135,6 +135,16 @@ class Domain(Base):
else:
return False
+ def check_mx(self):
+ try:
+ hostnames = app.config['HOSTNAMES'].split(',')
+ return any(
+ str(rset).split()[-1][:-1] in hostnames
+ for rset in dns.resolver.query(self.name, 'MX')
+ )
+ except Exception as e:
+ return False
+
def __str__(self):
return self.name
diff --git a/core/admin/mailu/ui/templates/domain/list.html b/core/admin/mailu/ui/templates/domain/list.html
index 0fa54f4f..5eb1a154 100644
--- a/core/admin/mailu/ui/templates/domain/list.html
+++ b/core/admin/mailu/ui/templates/domain/list.html
@@ -18,6 +18,7 @@
{% trans %}Domain name{% endtrans %} |
{% trans %}Mailbox count{% endtrans %} |
{% trans %}Alias count{% endtrans %} |
+ {% trans %}Status{% endtrans %} |
{% trans %}Comment{% endtrans %} |
{% trans %}Created{% endtrans %} |
{% trans %}Last edit{% endtrans %} |
@@ -42,6 +43,7 @@
{{ domain.name }} |
{{ domain.users | count }} / {{ domain.max_users or '∞' }} |
{{ domain.aliases | count }} / {{ domain.max_aliases or '∞' }} |
+ {{ 'ok' if domain.check_mx() else 'MX error' }} |
{{ domain.comment or '' }} |
{{ domain.created_at }} |
{{ domain.updated_at or '' }} |
diff --git a/core/admin/mailu/ui/views/domains.py b/core/admin/mailu/ui/views/domains.py
index 459902e2..7afc1746 100644
--- a/core/admin/mailu/ui/views/domains.py
+++ b/core/admin/mailu/ui/views/domains.py
@@ -90,23 +90,15 @@ def domain_signup(domain_name=None):
conflicting_domain = models.Domain.query.get(form.name.data)
conflicting_alternative = models.Alternative.query.get(form.name.data)
conflicting_relay = models.Relay.query.get(form.name.data)
- hostnames = app.config['HOSTNAMES'].split(',')
if conflicting_domain or conflicting_alternative or conflicting_relay:
flask.flash('Domain %s is already used' % form.name.data, 'error')
else:
- # Check if the domain MX actually points to this server
- try:
- mxok = any(str(rset).split()[-1][:-1] in hostnames
- for rset in dns.resolver.query(form.name.data, 'MX'))
- except Exception as e:
- mxok = False
- if mxok:
- # Actually create the domain
- domain = models.Domain()
- form.populate_obj(domain)
- domain.max_quota_bytes = app.config['DEFAULT_QUOTA']
- domain.max_users = 10
- domain.max_aliases = 10
+ domain = models.Domain()
+ form.populate_obj(domain)
+ domain.max_quota_bytes = app.config['DEFAULT_QUOTA']
+ domain.max_users = 10
+ domain.max_aliases = 10
+ if domain.check_mx():
db.session.add(domain)
if flask_login.current_user.is_authenticated:
user = models.User.query.get(flask_login.current_user.email)