If you’re sending an email without a request, such as a background task, you’ll need to identify the domain somehow. You could use an environment variables or you could use the django.contrib.sites framework. Here’s the specific bit of the docs on generating the URL using the sites framework. I suspect there are other options available, but those are the two I have typically reached for.
I normally use the sites framework, and ensure it’s properly configured.
Another option is to use an enviroment variable to set a custom setting that is “the site’s domain”, and use that to populate ALLOWED_HOSTS, your emails, etc. This avoids the database updates involved in using the sites framework.