1

I want to integrate the functionality to generate a HTML site using Wagtail tools such as the RichTextField (or StreamField) and send it as HTML email. Is there a straightforward way to render the Wagtail Page as html and send it using the Django email module?

More specifically, I thought of designing individual emails like individual blog entries as described in the Wagtail docs, thus:

from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel

class EmailPage(Page):
    email_body = RichTextField(blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('email_body', classname="full")
    ]

But instead of posting the individual entries as in the Wagtail blog example, I want to send these entries as HTML emails using Django email, like so:

from django.core.mail import send_mail
from django.template.loader import render_to_string

subject = 'test subject'
sender = 'my@email.com'
recipient = 'your@email.com'

body = render_to_string('email_template.html', {'content': content_from_wagtail})

send_mail(subject, body, sender, [recipient])

Thanks for your suggestions.

pinplex
  • 23
  • 5
  • Did you ever find a solution to this? – gsundberg Feb 06 '20 at 14:43
  • Unfortunately, I did not. I got distracted with other projects and this issue was/is not that urgent. Still it would be nice to have a solution to this. Please let me know if you make progress on this. Thanks. – pinplex Apr 28 '20 at 08:36

0 Answers0