Unlimited Email Sign-Ups for Free — Serverless Mailing Lists

Create a simple serverless function to collect email from your users for free without external tools

Riccardo Giorato
Nov 6 · 3 min read

What Are We Going to Build?

We’re going to build a simple HTML form with a serverless function to save all the emails from your users without any hard limit.

Web services that provide you the possibility to save email are usually limited to 1,000 or 2,000 emails with the free tiers, and we will solve this issue easily.

With our combination, we will get up to 125,000 new emails every month for free using Netlify functions or similar serverless hosting providers.

Saving a simple email from your users shouldn’t require you to buy any expensive or external tool.

Netlify offers forms submission, too, but only 100 basic submissions per month.


The Tech Stack

  • Free PostgreSQL database service like the one from ElephantSQL or from Heroku

The Back-End Code

We’re going to save the emails on a database — if you need a simple database with PostgreSQL, you can use the ElephantSQL free tier.

You can build a simple email_signup table with this SQL code:

You’ll need to host this node-simple serverless function somewhere. I suggest you use Netlify functions.

For the code, we’re going to use just a few basic modules to enable you to check the email validity without any external API:

  • disposable-email-domains: It’s a public module that gives you a complete list of temporary emails to prevent a user from using disposable emails

Remember to replace the connectionString with the connection URL from your database, in our case from ElephantSQL.

We also prevent SQL injection by using prepared statements with bound parameters in the saveEmailDB function:

  • const insertQuery = “INSERT INTO email_signup(email) VALUES($1)”;

With this Query, your users won’t be able to submit any other value inside this SQL command thanks to the bound set by the VALUES property.

We also handle various response like a 403 status code with an error message if the user sends a temporary email or one without a domain after the @.


The Front-End Code

The front-end code is just a simple HTML form, but that will send the email to our serverless function and will display the message sent from the server inside the result div.

The good thing is that the server handles everything, and you won’t need to update the front-end code but just the server with different messages.

Better Programming

Advice for programmers.

Thanks to Zack Shapiro

Riccardo Giorato

Written by

XR Developer and Photogrammetry Artist https://riccardogiorato.com/

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade