django-organizations icon indicating copy to clipboard operation
django-organizations copied to clipboard

HTML emails

Open alexcwatt opened this issue 6 years ago • 4 comments

I am implementing HTML emails for a project and noticed that although the email body templates end in .html, they are actually used as text templates. I think the ideal would be to have some default templates but ending in .txt, and letting the user override those as well as providing .html versions. Then if a .html version exists, it will be passed to Django's send_mail function.

Any thoughts on the best way to implement this, since changing from .html to .txt would break existing overrides?

alexcwatt avatar Aug 08 '17 13:08 alexcwatt

I can think of a couple ways of doing this.

One is having both text and HTML body templates. Another is allowing users to override how the email itself is generated. I'm a bit more partial to this - either it allows people to bring their own HTML email builder and/or basic HTML email handling is added via some new backend classes that ship with the app.

For what it's worth, I'm not against making a breaking change like changing the template from .html to .txt. It could be made in such a way that it isn't immediately breaking or just be documented as part of an upgrade.

bennylope avatar Aug 08 '17 15:08 bennylope

We could even do both: Let the user provide a .html or .txt version, but also write a new method that returns just the EmailMessage instance. They could then override that if needed.

alexcwatt avatar Aug 08 '17 19:08 alexcwatt

write a new method that returns just the EmailMessage instance

This sounds like a good strategy to start.

bennylope avatar Aug 09 '17 13:08 bennylope

Is this fixed? How to we go about sending a custom HTML email?

  email_message = self.email_message(
            user, self.invitation_subject, self.invitation_body, sender, **kwargs
        )

Where "invitation_body" here is a custom HTML email

avianion avatar Jul 11 '22 16:07 avianion