Skip to content

Commit

Permalink
Replace django-mailer with django-yubin
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed May 30, 2024
1 parent 3ddedd1 commit 8d24791
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 87 deletions.
2 changes: 1 addition & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ mozilla-django-oidc-db
django-open-forms-client
django-htmx
playwright
django-mailer
django-image-cropping
django-log-outgoing-requests
xsdata
django-setup-configuration
django-yubin

# django cms
django-cms
Expand Down
14 changes: 9 additions & 5 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ celery==5.4.0
# celery-once
# django-celery-beat
# django-celery-monitor
# django-yubin
# notifications-api-common
celery-once==3.0.1
# via -r requirements/base.in
Expand Down Expand Up @@ -118,7 +119,6 @@ django==4.2.11
# django-jsonform
# django-localflavor
# django-log-outgoing-requests
# django-mailer
# django-open-forms-client
# django-otp
# django-phonenumber-field
Expand Down Expand Up @@ -225,8 +225,6 @@ django-localflavor==3.1
# via -r requirements/base.in
django-log-outgoing-requests==0.6.1
# via -r requirements/base.in
django-mailer==2.3.1
# via -r requirements/base.in
django-open-forms-client==0.3.0
# via -r requirements/base.in
django-ordered-model==3.7.4
Expand Down Expand Up @@ -287,6 +285,8 @@ django-two-factor-auth[phonenumberslite,webauthn]==1.16.0
# via maykin-2fa
django-view-breadcrumbs==2.5.1
# via -r requirements/base.in
django-yubin==2.0.4
# via -r requirements/base.in
djangocms-admin-style==3.2.3
# via django-cms
djangocms-attributes-field==2.1.0
Expand Down Expand Up @@ -379,8 +379,6 @@ jsonschema==4.1.0
# via drf-spectacular
kombu==5.3.7
# via celery
lockfile==0.12.2
# via django-mailer
lxml==4.9.1
# via
# django-digid-eherkenning
Expand All @@ -390,6 +388,8 @@ lxml==4.9.1
# xmlsec
mail-editor==0.3.7
# via -r requirements/base.in
mail-parser==3.15.0
# via django-yubin
markdown==3.3.6
# via -r requirements/base.in
markuppy==1.14
Expand Down Expand Up @@ -478,6 +478,7 @@ python-stdnum==1.17
pytz==2021.3
# via
# -r requirements/base.in
# django-yubin
# djangorestframework
pyyaml==6.0
# via
Expand Down Expand Up @@ -507,6 +508,8 @@ requests==2.31.0
# zgw-consumers
sentry-sdk==1.38.0
# via -r requirements/base.in
simplejson==3.19.2
# via mail-parser
six==1.16.0
# via
# click-repl
Expand All @@ -515,6 +518,7 @@ six==1.16.0
# furl
# html5lib
# isodate
# mail-parser
# orderedmultidict
# python-dateutil
# qrcode
Expand Down
27 changes: 17 additions & 10 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ celery==5.4.0
# celery-once
# django-celery-beat
# django-celery-monitor
# django-yubin
# notifications-api-common
celery-once==3.0.1
# via
Expand Down Expand Up @@ -210,7 +211,6 @@ django==4.2.11
# django-jsonform
# django-localflavor
# django-log-outgoing-requests
# django-mailer
# django-open-forms-client
# django-otp
# django-phonenumber-field
Expand Down Expand Up @@ -379,10 +379,6 @@ django-log-outgoing-requests==0.6.1
# via
# -c requirements/base.txt
# -r requirements/base.txt
django-mailer==2.3.1
# via
# -c requirements/base.txt
# -r requirements/base.txt
django-open-forms-client==0.3.0
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -491,6 +487,10 @@ django-view-breadcrumbs==2.5.1
# -r requirements/base.txt
django-webtest==1.9.11
# via -r requirements/test-tools.in
django-yubin==2.0.4
# via
# -c requirements/base.txt
# -r requirements/base.txt
djangocms-admin-style==3.2.3
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -691,11 +691,6 @@ kombu==5.3.7
# celery
lazy-object-proxy==1.6.0
# via astroid
lockfile==0.12.2
# via
# -c requirements/base.txt
# -r requirements/base.txt
# django-mailer
lxml==4.9.1
# via
# -c requirements/base.txt
Expand All @@ -710,6 +705,11 @@ mail-editor==0.3.7
# via
# -c requirements/base.txt
# -r requirements/base.txt
mail-parser==3.15.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
# django-yubin
markdown==3.3.6
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -921,6 +921,7 @@ pytz==2021.3
# via
# -c requirements/base.txt
# -r requirements/base.txt
# django-yubin
# djangorestframework
pyyaml==6.0
# via
Expand Down Expand Up @@ -969,6 +970,11 @@ sentry-sdk==1.38.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
simplejson==3.19.2
# via
# -c requirements/base.txt
# -r requirements/base.txt
# mail-parser
six==1.16.0
# via
# -c requirements/base.txt
Expand All @@ -979,6 +985,7 @@ six==1.16.0
# furl
# html5lib
# isodate
# mail-parser
# orderedmultidict
# python-dateutil
# qrcode
Expand Down
27 changes: 17 additions & 10 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ celery==5.4.0
# celery-once
# django-celery-beat
# django-celery-monitor
# django-yubin
# notifications-api-common
celery-once==3.0.1
# via
Expand Down Expand Up @@ -249,7 +250,6 @@ django==4.2.11
# django-jsonform
# django-localflavor
# django-log-outgoing-requests
# django-mailer
# django-open-forms-client
# django-otp
# django-phonenumber-field
Expand Down Expand Up @@ -423,10 +423,6 @@ django-log-outgoing-requests==0.6.1
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-mailer==2.3.1
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-open-forms-client==0.3.0
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -539,6 +535,10 @@ django-webtest==1.9.11
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-yubin==2.0.4
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
djangocms-admin-style==3.2.3
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -787,11 +787,6 @@ lazy-object-proxy==1.6.0
# -c requirements/ci.txt
# -r requirements/ci.txt
# astroid
lockfile==0.12.2
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-mailer
locust==2.20.0
# via -r requirements/dev.in
lxml==4.9.1
Expand All @@ -808,6 +803,11 @@ mail-editor==0.3.7
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
mail-parser==3.15.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-yubin
markdown==3.3.6
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -1064,6 +1064,7 @@ pytz==2021.3
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-yubin
# djangorestframework
pyyaml==6.0
# via
Expand Down Expand Up @@ -1122,6 +1123,11 @@ sentry-sdk==1.38.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
simplejson==3.19.2
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# mail-parser
six==1.16.0
# via
# -c requirements/ci.txt
Expand All @@ -1133,6 +1139,7 @@ six==1.16.0
# geventhttpclient
# html5lib
# isodate
# mail-parser
# orderedmultidict
# python-dateutil
# qrcode
Expand Down
7 changes: 3 additions & 4 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@
"sessionprofile",
"openformsclient",
"django_htmx",
"mailer",
"log_outgoing_requests",
"formtools",
"django_setup_configuration",
"django_yubin",
# Project applications.
"open_inwoner.components",
"open_inwoner.kvk",
Expand Down Expand Up @@ -351,9 +351,8 @@

DEFAULT_FROM_EMAIL = config("DEFAULT_FROM_EMAIL", default="[email protected]")


EMAIL_BACKEND = "mailer.backend.DbBackend"
MAILER_EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_BACKEND = "django_yubin.backends.QueuedEmailBackend"
MAILER_USE_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

#
# LOGGING
Expand Down
25 changes: 8 additions & 17 deletions src/open_inwoner/configurations/emails.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from datetime import timedelta

from django.db.models import F
from django.utils import timezone

from django_yubin.models import Log
from mail_editor.helpers import find_template
from mailer.models import RESULT_SUCCESS, MessageLog

from open_inwoner.configurations.models import SiteConfiguration

Expand All @@ -14,25 +15,15 @@ def inform_admins_about_failing_emails():

if not inform_users:
return

now = timezone.now()
period_start = now - timedelta(days=1)

failed_email_objects = MessageLog.objects.filter(
when_attempted__gt=period_start
).exclude(result=RESULT_SUCCESS)

# wrap with what the existing mail-template expects
failed_email_logs = []
for log in failed_email_objects:
# re-use expensive pickled .email property
email = log.email
failed_email_logs.append(
{
"subject": email.subject,
"recipient": ", ".join(email.to),
"date": log.when_attempted,
}
)
failed_email_logs = (
Log.objects.filter(date__gt=period_start)
.annotate(subject=F("message__subject"), recipient=F("message__to_address"))
.values("subject", "recipient", "date")
)

if not failed_email_logs:
return
Expand Down
Loading

0 comments on commit 8d24791

Please sign in to comment.