Use mail_admins instead of send_mail.

This commit is contained in:
Víðir Valberg Guðmundsson 2024-08-03 20:53:18 +02:00
parent 4254baf09d
commit ca8987ba3b
3 changed files with 5 additions and 7 deletions

View file

@ -1,7 +1,6 @@
"""Loaded with the AppConfig.ready() method.""" """Loaded with the AppConfig.ready() method."""
from django.conf import settings from django.core.mail import mail_admins
from django.core.mail import send_mail
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from django.utils import timezone from django.utils import timezone
@ -15,11 +14,9 @@ from . import models
def check_total_amount(sender: models.Payment, instance: models.Payment, **kwargs: dict) -> None: # noqa: ARG001 def check_total_amount(sender: models.Payment, instance: models.Payment, **kwargs: dict) -> None: # noqa: ARG001
"""Check that we receive Payments with the correct amount.""" """Check that we receive Payments with the correct amount."""
if instance.amount != instance.order.total_with_vat: if instance.amount != instance.order.total_with_vat:
send_mail( mail_admins(
"Payment received: wrong amount", "Payment received: wrong amount",
f"Please check payment ID {instance.pk}", f"Please check payment ID {instance.pk}",
settings.DEFAULT_FROM_EMAIL,
settings.ADMINS,
) )

View file

@ -3,7 +3,7 @@
import stripe import stripe
from django.conf import settings from django.conf import settings
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core.mail import send_mail from django.core.mail import mail_admins
from django.db import transaction from django.db import transaction
from django.http import HttpRequest from django.http import HttpRequest
from django.http import HttpResponse from django.http import HttpResponse
@ -80,7 +80,7 @@ def order_pay(request: HttpRequest, order_id: int) -> HttpResponse:
cancel_url=base_domain + "/cancel", cancel_url=base_domain + "/cancel",
) )
except Exception as e: except Exception as e:
send_mail("Error in checkout", str(e), settings.DEFAULT_FROM_EMAIL, settings.ADMINS) mail_admins("Error in checkout", str(e))
raise raise
# TODO: Redirect with status=303 # TODO: Redirect with status=303

View file

@ -127,6 +127,7 @@ EMAIL_BACKEND = env.str(
default="django.core.mail.backends.console.EmailBackend", default="django.core.mail.backends.console.EmailBackend",
) )
DEFAULT_FROM_EMAIL = env.str("DEFAULT_FROM_EMAIL", default="") DEFAULT_FROM_EMAIL = env.str("DEFAULT_FROM_EMAIL", default="")
SERVER_EMAIL = env.str("SERVER_EMAIL", default=DEFAULT_FROM_EMAIL)
# Parse email URLs, e.g. "smtp://" # Parse email URLs, e.g. "smtp://"
email = env.dj_email_url("EMAIL_URL", default="smtp://") email = env.dj_email_url("EMAIL_URL", default="smtp://")
EMAIL_HOST = email["EMAIL_HOST"] EMAIL_HOST = email["EMAIL_HOST"]