'Currently we don\'t support accounts in multiple subdomains using
a single email address. We override this function so that we do
not send a reset link to an email address if the reset attempt is
done on the subdomain which does not match user.realm.subdomain.
Once we start supporting accounts with the same email in
multiple subdomains, we may be able to refactor this function.
A second reason we override this function is so that we can send
the mail through the functions in zerver.lib.send_email, to match
how we send all other mail in the codebase.'

def send_mail(self, subject_template_name, email_template_name, context, from_email, to_email, html_email_template_name=None):

    user = get_user_profile_by_email(to_email)
    attempted_subdomain = get_subdomain(getattr(self, 'request'))
    context['attempted_realm'] = False
    if (not check_subdomain(user.realm.subdomain, attempted_subdomain)):
        context['attempted_realm'] = get_realm(attempted_subdomain)
    send_email('zerver/emails/password_reset', to_user_id=user.id, from_name='Zulip    Account    Security', from_address=FromAddress.NOREPLY, context=context)
