bennylope / django-organizations

:couple: Multi-user accounts for Django projects
http://django-organizations.readthedocs.org/
BSD 2-Clause "Simplified" License
1.31k stars 212 forks source link

HTML emails #132

Open alexcwatt opened 7 years ago

alexcwatt commented 7 years ago

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?

bennylope commented 7 years ago

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.

alexcwatt commented 7 years ago

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.

bennylope commented 7 years ago

write a new method that returns just the EmailMessage instance

This sounds like a good strategy to start.

avianion commented 2 years ago

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