import re

from allauth.account.adapter import DefaultAccountAdapter
from django.conf import settings

from apps.contrib.emails import Email
from apps.users import USERNAME_INVALID_MESSAGE
from apps.users import USERNAME_REGEX


class UserAccountEmail(Email):
    def get_receivers(self):
        return [self.object]

    @property
    def template_name(self):
        return self.kwargs['template_name']

    def get_context(self):
        context = super().get_context()
        context['contact_email'] = settings.CONTACT_EMAIL
        return context


class AccountAdapter(DefaultAccountAdapter):
    username_regex = re.compile(USERNAME_REGEX)
    error_messages = dict(
        DefaultAccountAdapter.error_messages,
        invalid_username=USERNAME_INVALID_MESSAGE
    )

    def send_mail(self, template_prefix, email, context):
        user = context['user']
        return UserAccountEmail.send_sync(
            user,
            template_name=template_prefix,
            **context
        )

@@ -96,16 +96,68 @@
 ttings%0A%0A
+from adhocracy4.emails.mixins import SyncEmailMixin%0A
 from app
@@ -302,16 +302,32 @@
 il(Email
+, SyncEmailMixin
 ):%0A    d
@@ -970,13 +970,8 @@
 send
-_sync
 (%0A  

Use SyncEmailMixin for account mails