UP HOME

How I made a mailing list

[2025-11-10 Mon]

In this post, I'll walk through how I built a simple mailing list using tools I already know and some I don't know without relying on external services.

I've used newsletter services before, like mailchimp and beehiiv, they are free, reliable and pretty much do the job without hassle.

I figured it would be nice to make a mailing list to share my new posts and get feedback (please don't hesitate to reply and point out my mistakes). And I said why not build it myself, it's a new exercise for me and I started it with the hope to make it functional and I've learned many things along the way.

So last weekend I've spent most of my time studying how to make it possible using the tools I have, I wanted to rely as much as possible on the tools I already know and that are available right away. So to build my mailing list, here are the ingredients:

In the following article I'll present to you the current workflow of my mailing list, how I've built it and the challenges I've faced.

The subscription form

HTML + PHP

Nothing fancy just a classic HTML form with two inputs, name and email, some builtin form verification and a submit button to send a POST request to /subscribe

I've not been in contact with PHP since my Engineering school years, so I needed to brush up on PHP before building something.

I picked up PHP because it's an established language, so it won't be hard to find help and I wasn't disappointed the PHP documentation was more than enough to meet my needs. It's very well done, with examples and a search bar that is super useful.

In no time I had my php script retrieving the user inputs, do the necessary sanitizing and communicate with my postgresql database.

Nginx

I'm hosting this website on my own Linux machine at home using nginx, I'm a newbie to self-hosting, and I've used the minimal "Hello world!" configuration to serve my website so far. But with great power comes great responsibility, and I had to tweak nginx to make it more secure.

local server

Here lives this website and its database.

At first I've tried serving my php scripts without touching anything on my nginx configuration, Big mistake, the php scripts were served as plain text documents. With a bit of research I've discovered FastCGI, it's a binary protocol for interfacing interactive programs with a web server, in this case nginx.

I learned that Nginx doesn't interpret PHP by default, you need FastCGI for that, and now I understand how the web server delegates script execution securely.

Basically the php scripts are interpreted by the use of fastcgi_pass unix:/run/php/php8.3-fpm.sock; by a php socket before landing on the user-end. This way I made sure that my PHP scripts are not served as plain text.

PostgreSQL + Bash

PostgreSQL is the database system used by both small and large projects. I'm familiar with its syntax so it was my comfort pick. I started by creating a ROLE for a user with limited access, created a database for this user, and created the mailing list table with email, name and id. Then to populate the table I use a bash script to have on hand a CLI tool that does the basic operations of getting the list of subscribers, insert a new email or delete an email.

I use bash because I'm not searching for any external programs unless it's really necessary, because there are so many powerful things Bash can do. I really recommend you to give the pure bash bible a look. It documents various methods to accomplish tasks with only built-in bash features, removing this way unneeded dependencies from scripts.

last step was setting up some cron jobs to execute some scripts in order to retrieve and refresh the mailing list every once in a while.

How to send emails

Emacs + SMTP

Having a mailing list is good, but sending them mails is better.

Since I have a domain name, I was looking into hosting my own mail service, but it's very complicated and needs a lot of work. So I'll leave it for another time.

In the meantime, I've created an account with Zoho with their Forever free plan which is nice.

Once the account is created, it was time for a bit of Emacs manual reading, I've configured smtp with Emacs as I'll be using it as my mail client.

The reason behind this choice, is that zoho web interface isn't ideal for bulk sending individual emails. And it's much easier to bulk send email programmatically with elisp. I've coded a function that loops through a file containing the emails of the recipients and sending personalized messages. The only limit I see to this method is that it creates a buffer per recipient, which I don't know how Emacs will react to it if the mailing list grows, but we'll see, I'm limit-testing the number of buffers Emacs can handle.

The idea is to stick to the plan I've defined to myself and use tools I already have in hand. I'm well aware that a python script with an external package would have been easier.

You can subscribe now

This experiment is part of my learn-in-public journey, so if you spot mistakes, have questions, or want to share how you'd approach things differently, I'd love to hear from you.

And if you'd like to see how this project evolves, you can subscribe to get future posts straight to your inbox.


Subscribe to get future posts via email


Copyright © 2025 Abderrahmane Faiz

learn_in_public@afaiz.dev