From ca8987ba3b2f46f88436038b487a9d65bceb7059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sat, 3 Aug 2024 20:53:18 +0200 Subject: [PATCH] Use mail_admins instead of send_mail. --- src/accounting/signals.py | 7 ++----- src/accounting/views.py | 4 ++-- src/project/settings.py | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/accounting/signals.py b/src/accounting/signals.py index f33263d..0746206 100644 --- a/src/accounting/signals.py +++ b/src/accounting/signals.py @@ -1,7 +1,6 @@ """Loaded with the AppConfig.ready() method.""" -from django.conf import settings -from django.core.mail import send_mail +from django.core.mail import mail_admins from django.db.models.signals import post_save from django.dispatch import receiver 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 """Check that we receive Payments with the correct amount.""" if instance.amount != instance.order.total_with_vat: - send_mail( + mail_admins( "Payment received: wrong amount", f"Please check payment ID {instance.pk}", - settings.DEFAULT_FROM_EMAIL, - settings.ADMINS, ) diff --git a/src/accounting/views.py b/src/accounting/views.py index acfc077..7d2a8ad 100644 --- a/src/accounting/views.py +++ b/src/accounting/views.py @@ -3,7 +3,7 @@ import stripe from django.conf import settings 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.http import HttpRequest from django.http import HttpResponse @@ -80,7 +80,7 @@ def order_pay(request: HttpRequest, order_id: int) -> HttpResponse: cancel_url=base_domain + "/cancel", ) 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 # TODO: Redirect with status=303 diff --git a/src/project/settings.py b/src/project/settings.py index 2f78775..4f558a1 100644 --- a/src/project/settings.py +++ b/src/project/settings.py @@ -127,6 +127,7 @@ EMAIL_BACKEND = env.str( default="django.core.mail.backends.console.EmailBackend", ) 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://" email = env.dj_email_url("EMAIL_URL", default="smtp://") EMAIL_HOST = email["EMAIL_HOST"]