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.