Skip to content

Instantly share code, notes, and snippets.

@ja0nz
Last active February 21, 2026 15:36
Show Gist options
  • Select an option

  • Save ja0nz/35368f689f2a30c444b0a28569ca555c to your computer and use it in GitHub Desktop.

Select an option

Save ja0nz/35368f689f2a30c444b0a28569ca555c to your computer and use it in GitHub Desktop.
Gratis yet versatile email pipeline

Abstract

This is a short description of an email system which allows complex preprocessing and filtering without paying a cent.

What to expect:

  • Custom domain
  • Unlimited email aliases
  • Email monitoring
  • Spam protection
  • Filtering

Prerequisites

Obviously you need a domain which needs to be bought or onboarded to a Cloudflare account. Then head over to Email Routing and enable it, automatically creating all the MX / TXT settings with one click. Secondly you need a (free) generic email provider. An obvious choice may be Gmail or Outlook, but since I try to de-corporatize as much as possible I settled with https://www.infomaniak.com/en/free-email, offering a generous 20GB storage and supporting IMAP/SMTP in its free version, which is not taken for granted.

First Act: Hello Cloudflare

As indicated earlier, Cloudflare is the first link in this chain. Why so? Well, it's a reliable first recipient and offers something called Email Workers, which is a super developer-friendly way of defining routes, filters, and monitoring them. Take this example of mine, having a randomize 3-words catchall email worker used for transactional emails:

async email(message, env, ctx) {
  // Regex: Exactly 3 words separated by '.' followed by @domain.com
  // Usage: thicket.juggle.revival@domain.com -> will be forwarded
  //        alkjelkjf@domain.com              -> will not
  const pattern = /\b[a-z0-9]+\.[a-z0-9]+\.[a-z0-9]+@domain\.com\b/i;

  // Collect all possible recipient fields
  const recipients = [
    message.to,                    // Primary recipient
    message.headers.get("to"),     // To header
    message.headers.get("cc"),     // CC header
    message.headers.get("bcc"),    // BCC header (mostly empty in Cloudflare)
  ].filter(Boolean); // Null/undefined removal

  // Check if recipient is matching
  const shouldForward = recipients.some((field) => pattern.test(field));

  if (shouldForward) {
    // Forward this email to our email address (optionally with +suffix)
    await message.forward("user+transactional@gmail.com");
  }
},

Just an example of what you could potentially do. One-to-one mappings like mail@domain.com -> user+important@gmail.com are available as well, along with drop email functions and much more.

Second Act: Hello Inbox

So by now the relayed emails should hit your inbox. Great. Time to set up the inbox filters. Many providers offer some rudimentary filtering in their email clients and, depending on your demands, you could be just fine with that. The real power starts with a "real" email client like Thunderbird, where you can set up email filtering based on Email Headers.

Remember I used the '+' sign earlier? A +sign email alias (or subaddressing) allows you to create instant, disposable variations of your email address by adding a + sign and a keyword before the @ symbol (e.g., user+shopping@gmail.com). These emails go directly to your primary inbox, making it easy to filter, organize, or block spam.

Staying with our example: user+transactional@gmail.com This email receives a high load of mildly interesting newsletters. You can bucket all those emails by creating a header filter Delivered-To: user+transactional@gmail.com. Notice that you can't just create a simple To or CC filter, as the original recipient is your @domain.com and not Gmail/Outlook etc.

Third Act: Reply with Style

By now you should be able to allocate emails based on importance or interest. Your inbox looks great. The only topic left is sending emails. As Cloudflare is just our receiver, it cannot be our sender. So the choice is again yours, be it Gmail/Outlook or something completely different.

I chose to go with https://www.smtp2go.com/ here, as they offer a generous free tier. Again you have to go through the process of setting up the right records for your domain.com, but every service guides and verifies you through this. Big providers allow you to Send mail as / treat as alias utilizing their own SMTP infrastructure though I highly recommend a real SMTP server in your DNS records as it does not restrict you on predefined aliases.

The last part is to configure your email client with the SMTP connection data, and your €0 email pipeline should work like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment