Skip to content

Commit 15e3154

Browse files
remove EMAIL_BACKEND from app settings (#43)
* remove EMAIL_BACKEND from app settings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7764d9b commit 15e3154

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
`django-email-relay` enables Django projects without direct access to a preferred SMTP server to use that server for email dispatch.
1111

12-
It consists of two parts:
12+
It consists of two parts:
1313

1414
1. A Django app with a custom email backend that stores emails in a central database queue. This is what you will use on all the distributed Django projects that you would like to give access to the preferred SMTP server.
1515

src/email_relay/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@dataclass
1313
class AppSettings:
1414
DATABASE_ALIAS: str = EMAIL_RELAY_DATABASE_ALIAS
15-
EMAIL_BACKEND: str = "django.core.mail.backends.smtp.EmailBackend"
1615
EMAIL_MAX_BATCH: int | None = None
1716
EMAIL_MAX_DEFERRED: int | None = None
1817
EMAIL_MAX_RETRIES: int | None = None

src/email_relay/relay.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from itertools import chain
77
from socket import error as socket_error
88

9+
from django.conf import settings
910
from django.core.mail import get_connection
1011
from django.db import transaction
1112

@@ -18,8 +19,6 @@
1819
def send_all():
1920
logger.info("sending emails")
2021

21-
connection = get_connection(backend=app_settings.EMAIL_BACKEND)
22-
2322
counts = {
2423
"sent": 0,
2524
"deferred": 0,
@@ -40,6 +39,8 @@ def send_all():
4039
logger.debug(msg)
4140
message_batch = message_batch[: app_settings.EMAIL_MAX_BATCH]
4241

42+
connection = None
43+
4344
for message in message_batch:
4445
with transaction.atomic():
4546
try:
@@ -52,7 +53,12 @@ def send_all():
5253
continue
5354
try:
5455
if connection is None:
55-
connection = get_connection(backend=app_settings.EMAIL_BACKEND)
56+
relay_email_backend = getattr(
57+
settings,
58+
"EMAIL_BACKEND",
59+
"django.core.mail.backends.smtp.EmailBackend",
60+
)
61+
connection = get_connection(backend=relay_email_backend)
5662
email = message.email
5763
if email is not None:
5864
email.connection = connection

0 commit comments

Comments
 (0)