summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMike Edmunds <medmunds@gmail.com>2025-07-16 15:01:49 -0700
committernessita <124304+nessita@users.noreply.github.com>2025-07-17 14:01:16 -0300
commitfc793fc303a3d516ab51bb21aa317031caabe7b4 (patch)
treedfcb559adacc3b5dd7e276a4d3b4740a06dc7064 /django
parent5289ce65b9a1963707767cc11c476679ab445135 (diff)
Fixed #36163 -- Deprecated most positional arguments in django.core.mail.
In public mail APIs, changed less frequently used parameters from keyword-or-positional to keyword-only, emitting a warning during the required deprecation period.
Diffstat (limited to 'django')
-rw-r--r--django/core/mail/__init__.py42
-rw-r--r--django/core/mail/message.py38
2 files changed, 69 insertions, 11 deletions
diff --git a/django/core/mail/__init__.py b/django/core/mail/__init__.py
index e822f1d2a2..4f49d85756 100644
--- a/django/core/mail/__init__.py
+++ b/django/core/mail/__init__.py
@@ -24,7 +24,7 @@ from django.core.mail.message import (
make_msgid,
)
from django.core.mail.utils import DNS_NAME, CachedDnsName
-from django.utils.deprecation import RemovedInDjango70Warning
+from django.utils.deprecation import RemovedInDjango70Warning, deprecate_posargs
from django.utils.functional import Promise
from django.utils.module_loading import import_string
@@ -49,7 +49,8 @@ __all__ = [
]
-def get_connection(backend=None, fail_silently=False, **kwds):
+@deprecate_posargs(RemovedInDjango70Warning, ["fail_silently"])
+def get_connection(backend=None, *, fail_silently=False, **kwds):
"""Load an email backend and return an instance of it.
If backend is None (default), use settings.EMAIL_BACKEND.
@@ -61,11 +62,22 @@ def get_connection(backend=None, fail_silently=False, **kwds):
return klass(fail_silently=fail_silently, **kwds)
+@deprecate_posargs(
+ RemovedInDjango70Warning,
+ [
+ "fail_silently",
+ "auth_user",
+ "auth_password",
+ "connection",
+ "html_message",
+ ],
+)
def send_mail(
subject,
message,
from_email,
recipient_list,
+ *,
fail_silently=False,
auth_user=None,
auth_password=None,
@@ -97,8 +109,22 @@ def send_mail(
return mail.send()
+@deprecate_posargs(
+ RemovedInDjango70Warning,
+ [
+ "fail_silently",
+ "auth_user",
+ "auth_password",
+ "connection",
+ ],
+)
def send_mass_mail(
- datatuple, fail_silently=False, auth_user=None, auth_password=None, connection=None
+ datatuple,
+ *,
+ fail_silently=False,
+ auth_user=None,
+ auth_password=None,
+ connection=None,
):
"""
Given a datatuple of (subject, message, from_email, recipient_list), send
@@ -166,8 +192,11 @@ def _send_server_message(
mail.send(fail_silently=fail_silently)
+@deprecate_posargs(
+ RemovedInDjango70Warning, ["fail_silently", "connection", "html_message"]
+)
def mail_admins(
- subject, message, fail_silently=False, connection=None, html_message=None
+ subject, message, *, fail_silently=False, connection=None, html_message=None
):
"""Send a message to the admins, as defined by the ADMINS setting."""
_send_server_message(
@@ -180,8 +209,11 @@ def mail_admins(
)
+@deprecate_posargs(
+ RemovedInDjango70Warning, ["fail_silently", "connection", "html_message"]
+)
def mail_managers(
- subject, message, fail_silently=False, connection=None, html_message=None
+ subject, message, *, fail_silently=False, connection=None, html_message=None
):
"""Send a message to the managers, as defined by the MANAGERS setting."""
_send_server_message(
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index 51af560b12..93269d0310 100644
--- a/django/core/mail/message.py
+++ b/django/core/mail/message.py
@@ -17,6 +17,7 @@ from pathlib import Path
from django.conf import settings
from django.core.mail.utils import DNS_NAME
+from django.utils.deprecation import RemovedInDjango70Warning, deprecate_posargs
from django.utils.encoding import force_bytes, force_str, punycode
# Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from
@@ -202,12 +203,24 @@ class EmailMessage:
mixed_subtype = "mixed"
encoding = None # None => use settings default
+ @deprecate_posargs(
+ RemovedInDjango70Warning,
+ [
+ "bcc",
+ "connection",
+ "attachments",
+ "headers",
+ "cc",
+ "reply_to",
+ ],
+ )
def __init__(
self,
subject="",
body="",
from_email=None,
to=None,
+ *,
bcc=None,
connection=None,
attachments=None,
@@ -455,12 +468,25 @@ class EmailMultiAlternatives(EmailMessage):
alternative_subtype = "alternative"
+ @deprecate_posargs(
+ RemovedInDjango70Warning,
+ [
+ "bcc",
+ "connection",
+ "attachments",
+ "headers",
+ "alternatives",
+ "cc",
+ "reply_to",
+ ],
+ )
def __init__(
self,
subject="",
body="",
from_email=None,
to=None,
+ *,
bcc=None,
connection=None,
attachments=None,
@@ -478,12 +504,12 @@ class EmailMultiAlternatives(EmailMessage):
body,
from_email,
to,
- bcc,
- connection,
- attachments,
- headers,
- cc,
- reply_to,
+ bcc=bcc,
+ connection=connection,
+ attachments=attachments,
+ headers=headers,
+ cc=cc,
+ reply_to=reply_to,
)
self.alternatives = [
EmailAlternative(*alternative) for alternative in (alternatives or [])