Creating a selfhosted newsletter with ProcessWire and MailGun
While I'm writing this I realize that I haven't published a blog post regarding the (proper) launch of accessible-app.com. That's very odd considering that I covered every other phase of this project here. Anyway:
Accessible App has launched! I rewrote the pattern articles, put the "What makes web-apps special" text there to provide context, explained how to contribute - and hopefully made the project's intention and layout a little bit more clear. Also, it's built with Gatsby and of course on GitHub.
But enough of the blog-housekeeping. This article is about setting up a ProcessWire-based selfhosted newsletter, so here we go:
In the past, I would just have chosen MailChimp or the like. Using these services, it only would have taken me minutes to set up a newsletter infrastructure. But my attitude towards services like these has changed: If possible, I now try to self-host. On one hand, to avoid rising costs once the mailing list gets bigger, on the other hand, to have as much control as possible over the subscriber e-mail addresses. Control, as in care, as in: 'People trust me with their email addresses, and I don't want to disappoint them.'
I remembered that I read about Matthias Ott's self-hosted prototyping.news setup in the past and I reached out to him via twitter. He was so kind to describe in great detail. So my first try was to follow his route. Setting up a Digital Ocean machine was very comfortable, unfortunately installing MailTrain less so. Server setup, wrangling with node.js on the server et cetera isn't my pet peeve, and maybe it never will be. I felt like that there must be an easier way out there.
Realization: I could just use ProcessWire 🤦
And there was - hidden in plain sight. Although I rarely mention ProcessWire on twitter or this blog anymore, I regularly build web sites and (for the server side) web-applications with this great CMS. And I'm of course subscribed to the official ProcessWire newsletter where Teppo and Ryan keep the community updated about core updates, fantastic new modules, forum activities and inspiring sites built with ProcessWire (on this occasion: thank you both for your excellent and constant work!). The newsletter itself is sent with ProcessWire and framework creator Ryan Cramer just released the underlying module "ProMailer" earlier this year.
The setup for accessible-app.com's newsletter consists of four parts:
- The newsletter signup form in Gatsby. Nothing exciting
- A - more or less - blank ProcessWire installation at newsletter.accessible-app.com (again, nothing exciting to see there). This installation has ProMailer installed. The signup form on the Gatsby site sends subscribers to the ProcessWire page, ProMailer takes care of double opt-in (read: sending a confirmation mail). The module takes care of creating subscriber lists (I got two: the real one and a list for testing), unsubscription management, and of course, authoring e-mails
- I decided against using PHP's
mail()function since I haven't had good experiences with it in the past. So, for the actual sending of the emails (be it confirmation ones or the newsletter issues themselves) I use MailGun. They offer a free account with 10,000 emails free every month. For the time being, this will be more than enough, I guess. And even if the list grows, their pricing is pay-as-you-go and looks reasonable.
One last word about ProMailer: While ProcessWire is open-source ProMailer is a commercial module - and I'm totally fine with it. My strategy is to purchase every official commercial module, no matter if I'm going to use it or not. I see it as a strategy to support Ryan Cramer and the team behind ProcessWire. This systems architecture, flexibility, performance and security has helped me build great customer projects in the past. Plus: even apart from that ProMailer is totally worth the money - and this actually applies to all commercial modules.