How the Wagtail newsletter package came to be
Find out how the wagtail-newsletter package came to life
Earlier this year, Freedom of the Press Foundation (FPF) approached Torchbox to see how we could help them deliver website articles to subscribers’ inboxes, because their existing distribution channels (including one formerly called Twitter) weren’t working so well any more. They are a longtime Wagtail shop, and they already have a strong newsletter audience, so it was natural for us to build on that.
Enter the wagtail-newsletter package, which I demoed at the recent What’s New in Wagtail webinar. With this package, editors can send Wagtail pages as newsletters as well as manage the recipients, campaigns, and other aspects of their emails.
The world of newsletter platforms is vast, and we didn’t want our package locked in to a single vendor, so there’s an internal API to plug different campaign backends into the package and support different vendors. We’ve started with Mailchimp, since it’s quite popular and also what FPF was already using.
Writing content for a newsletter is not that different from writing content for a web page, and often you’ll want to publish the same content through multiple channels. The package extends a page model of your choice to double as a newsletter. Once you have that set up, you can use the editor preview to show the email version of the content and you can use the editor controls to pick newsletter recipients, send a test email to yourself, send the campaign to subscribers, and then track the email performance. You can schedule newsletter sends too.
So what about HTML templates for your email newsletter? It’s notoriously difficult to generate HTML that renders properly across email clients, but you also want your email to look modern and reflect your brand. Thankfully, there’s no need to reinvent this particular wheel; we used MJML, a language and rendering tool developed by Mailjet, which deals with the table layout hacks that we’d rather forget. And to spice things up, we used mrml, a Rust reimplementation of the rendering tool that doesn’t depend on a NodeJS runtime and is very fast and thrifty with memory.
My favorite part of the project was crafting the UI. When you click on one of the newsletter buttons (“Send test email”, “Send campaign”, etc.), a Stimulus controller will display a confirmation dialog. When you click “Send”, another controller will send back an event to the original button that was clicked to submit the editor form. This decoupled approach works seamlessly with the new concurrent editing notifications and lines up with the adoption of Stimulus in Wagtail itself.
wagtail-newsletter is, of course, open source, with documentation to get you started. We hope you’ll find it useful during these difficult times, when journalism is overworked and under-appreciated, to stay in touch with your core audience. We’d love to hear about your experiences, either on the project’s issue tracker, or the Wagtail Slack. Also, if you have any interest in helping us add new email service providers, please get in touch.
This Week in Wagtail
A weeklyish newsletter with Wagtail tips, news, and more.