diff --git a/anymail/message.py b/anymail/message.py index caab121..1341c85 100644 --- a/anymail/message.py +++ b/anymail/message.py @@ -28,7 +28,7 @@ class AnymailMessageMixin(object): self.template_id = kwargs.pop('template_id', UNSET) self.merge_data = kwargs.pop('merge_data', UNSET) self.merge_global_data = kwargs.pop('merge_global_data', UNSET) - self.anymail_status = None + self.anymail_status = AnymailStatus() # noinspection PyArgumentList super(AnymailMessageMixin, self).__init__(*args, **kwargs) diff --git a/docs/sending/anymail_additions.rst b/docs/sending/anymail_additions.rst index 0f75a94..9baffd2 100644 --- a/docs/sending/anymail_additions.rst +++ b/docs/sending/anymail_additions.rst @@ -212,6 +212,19 @@ ESP send status :class:`~django.core.mail.EmailMessage`, with a normalized version of the ESP's response. + Anymail backends create this attribute *as they process each message.* + Before that, anymail_status won't be present on an ordinary Django + EmailMessage or EmailMultiAlternatives---you'll get an :exc:`AttributeError` + if you try to access it. + + This might cause problems in your test cases, because Django + `substitutes its own locmem email backend`_ during testing (so anymail_status + won't be set even after sending). Your code should either guard against + a missing anymail_status attribute, or use :class:`AnymailMessage` + (or the :class:`AnymailMessageMixin`) which initializes its anymail_status + attribute to a default AnymailStatus object. + + After sending through an Anymail backend, :attr:`~AnymailMessage.anymail_status` will be an object with these attributes: .. attribute:: message_id @@ -308,6 +321,10 @@ ESP send status message.anymail_status.esp_response.json() +.. _substitutes its own locmem email backend: + https://docs.djangoproject.com/en/stable/topics/testing/tools/#email-services + + .. _inline-images: Inline images