ui / django-post_office

A Django app that allows you to send email asynchronously in Django. Supports HTML email, database backed templates and logging.
MIT License
1.01k stars 268 forks source link

Premailer integration #287

Open yakky opened 4 years ago

yakky commented 4 years ago

A nice improvements it would be to provide a premailer integration and / or an overridable renderer which allows to customize the template rendering (https://github.com/ui/django-post_office/blob/master/post_office/models.py#L98)

I can work on this, if it's of interest

jrief commented 4 years ago

A premailer seems interesting – what exactly would you like to transform with it?

django-post_office already has an integrated renderer. This has been added to render images as inlines into the mail body.

yakky commented 4 years ago

Premailer goes beyond that, by inlining css, prepending domain to domainless urls etc (see https://github.com/peterbe/premailer).

I agree that probably the premailer integration can be added to PostOfficeTemplates template backend

Mogost commented 4 years ago

That is nice idea. Currently i use django-inlinecss for css styles inlining and some custom templatetags to prepend domain in my projects. Probably everyone who works with django-post_office has to do something similar. The idea of having this feature out of the box is beautiful in itself, and details can be discussed in PR.

yakky commented 4 years ago

@Mogost thanks for the reply. Just a few preliminary questions:

I think I can have something working in a week or so

Mogost commented 4 years ago

For me:

do you think PostOfficeTemplates backend is the right place to implement it?

right

should it be an optional dependency or a required one?

optional

jrief commented 4 years ago

I share @Mogost 's opinion:

  • do you think PostOfficeTemplates backend is the right place to implement it?

yes

  • should it be an optional dependency or a required one?

optional

jrief commented 4 years ago

btw., this feature will increase the version number to at least 3.3. What about dropping support for Python-2 there completely?

Mogost commented 4 years ago

@jrief I may have misunderstood you, but the support of Py2 was droped in my PR https://github.com/ui/django-post_office/pull/283

jrief commented 4 years ago

@Mogost Ups, forgot that – sorry.

selwin commented 4 years ago

A few thoughts:

  1. I like the idea of integrating something like premailer, but I'm not sure if it should be implemented as a template backend. Implementing it as a template backend means it will be called for every email that's sent and that would be very CPU intensive.

Maybe we can apply it as a template post processing step? Everytime a template is updated, we produce a "compiled" version and use that compiled version during delivery. But I wonder if this approach will work for all kinds of email.

  1. django-inlinecss mentioned by @Mogost seems easier to integrate because it's already a Django project.

  2. Perhaps we can also bring in a few commonly used email related template tags (like prepending domains) to post office.

selwin commented 4 years ago

This is another library that I always use in my projects dealing with emails: https://github.com/SeiryuZ/django-pancake

This allows us to use Django template tags like include and extends in our source code for parts like footer and headers. We then flatten our emails into one single template before putting them into post office.