Skip to content

Conversation

@alexei
Copy link
Contributor

@alexei alexei commented Nov 30, 2025

According to the Django docs on sending email the outbox attribute is:

a list with an EmailMessage instance for each message that would be sent.

When you send single-message emails, they are direct instances of EmailMessage. When the emails are multipart, they are instances of EmailMultiAlternatives. While EmailMultiAlternatives inherits from EmailMessage, declaring outbox as list[EmailMessage is only partially correct, because the EmailMultiAlternatives introduces some properties and methods of its own, such as alternatives. If you access any of them, the type checker will complain. I think, thus, the correct type is:

outbox: list[EmailMessage | EmailMultiAlternatives]

@alexei
Copy link
Contributor Author

alexei commented Nov 30, 2025

On another note, I'm not sure EmailMultiAlternatives.alternatives is correctly typed as list[tuple[bytes | EmailMessage | Message | SafeMIMEText | str, str]], when Django seems to create a list of EmailAlternatives:

https://github.com/django/django/blob/85586052e8d1d9f160b9f1b351e61a787a8e4bed/django/core/mail/message.py#L479-L481

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant