summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/5.2.txt4
-rw-r--r--docs/topics/email.txt20
2 files changed, 24 insertions, 0 deletions
diff --git a/docs/releases/5.2.txt b/docs/releases/5.2.txt
index 61101ce1fd..8b77ecc482 100644
--- a/docs/releases/5.2.txt
+++ b/docs/releases/5.2.txt
@@ -143,6 +143,10 @@ Email
<django.core.mail.EmailMultiAlternatives.alternatives>` is now a list of
named tuples, as opposed to regular tuples.
+* The new :meth:`~django.core.mail.EmailMultiAlternatives.body_contains` method
+ returns a boolean indicating whether a provided text is contained in the
+ email ``body`` and in all attached MIME type ``text/*`` alternatives.
+
Error Reporting
~~~~~~~~~~~~~~~
diff --git a/docs/topics/email.txt b/docs/topics/email.txt
index 635864a95e..e5d4f277f5 100644
--- a/docs/topics/email.txt
+++ b/docs/topics/email.txt
@@ -436,6 +436,26 @@ Django's email library, you can do this using the
msg.attach_alternative(html_content, "text/html")
msg.send()
+ .. method:: body_contains(text)
+
+ .. versionadded:: 5.2
+
+ Returns a boolean indicating whether the provided ``text`` is
+ contained in the email ``body`` and in all attached MIME type
+ ``text/*`` alternatives.
+
+ This can be useful when testing emails. For example::
+
+ def test_contains_email_content(self):
+ subject = "Hello World"
+ from_email = "from@example.com"
+ to = "to@example.com"
+ msg = EmailMultiAlternatives(subject, "I am content.", from_email, [to])
+ msg.attach_alternative("<p>I am content.</p>", "text/html")
+
+ self.assertIs(msg.body_contains("I am content"), True)
+ self.assertIs(msg.body_contains("<p>I am content.</p>"), False)
+
Updating the default content type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~