website/content/posts/domainandemail.md
Eduardo Figueroa 4e5386354f
Update blog posts: clean up formatting, fix typos, add new posts
- FFB.md: Fix typos, normalize tags/categories to lowercase, replace *** with --- for horizontal rules, trim trailing whitespace
- contacting-me.md: Add mailto link for email, improve spacing and formatting
- domainandemail.md: Fix typos (regitrar, programmaticaly, Malgun, teir), normalize tags/categories, clean up nested list formatting, remove redundant horizontal rules
- rss.md: Reword intro sentence, clarify RSSHub description, fix trailing whitespace, remove duplicate selfhosted tag
- stack.md: Convert frontmatter from TOML (+++) to YAML (---), normalize tags/categories, minor copy edits
- rosterhash.md: New post about RosterHash fantasy football schedule viewer project
- rr-rss-nag.md: New post explaining how to bypass RoyalRoad piracy nags in FreshRSS feeds using CSS selectors
- security-groups.md: New post walking through the evolution of formatting AWS security groups in Terraform across three iterations
2026-02-05 15:45:40 -08:00

4.3 KiB

title date tags categories
Custom Domain and Emails 2024-10-07
dns
email
selfhosted

What is this?

Let's say you wanted to buy a domain like edfig.dev. You can host a personal blog at this address. Once you buy the domain, not only can you host content, but with a bit more tinkering you can send and receive emails with it.

You can email eddie@edfig.dev or admin@edfig.dev and that email will make its way to my inbox. You can set up rules to handle specific addresses too.

You'll need to create accounts for the following:

  • Mailgun.com
  • porkbun.com

Setting it up

1. The Domain

You can buy a domain from any registrar, I recommend PorkBun or Cloudflare. I'll be using Porkbun for this discussion.

Pricing will depend on the name and what TLD (the .com part). I occasionally run into issues with sites not recognizing eddie@fig.systems as a valid email address because it's a lesser known domain.

Once you have it you can enter DNS records to where you host stuff or start using it for email.

2. The Email

Email is one of those things you shouldn't host yourself, it's very annoying. But luckily there are services out there that take care of most of the hassle. MailGun and SendGrid are two such services. I'll be using Mailgun here.

With Mailgun I can:

  • Receive emails at custom email addresses with my domain
  • Route those emails based on rules
    • e.g. Emails sent to no-reply@edfig.dev are completely dropped
  • Send emails AS those email addresses through gmail
    • Receive an email at admin@edfig.dev at my regular gmail account and reply as admin@fig.systems
  • Use their API to programmatically send emails
  • Use their SMTP servers to send as custom email addresses
    • My self hosted services send notification emails as no-reply@fig.systems or as service_name@fig.systems

3. Setting up DNS

  1. Buy a domain at porkbun.

Pick your favorite. I'll be using figgy.foo for this, there was a good deal on it.

  1. Log into Mailgun
  • Go to Send -> Sending -> Domains
  • Click on "Add New Domain"
  • Add figgy.foo, leave the rest blank, click Add Domain
  1. Add DNS records to porkbun.

You'll be provided with records for sending, receiving, and tracking.

In Porkbun Domain Management select DNS when you hover over your new domain.

Copy the entries over. Make sure the Types match and that you leave off the figgy.foo portion in the host field in porkbun. Anything you add in the host field will automatically append your domain to the end of it. If the field is just figgy.foo then leave the host field blank.

Copy all the Value fields from Mailgun to the Answer field in Porkbun and then click on Verify at the top right. You should see the status change to Active.

This is what your records in porkbun should look like.

porkbun-email-dns-records

4. Setting up Mailgun

Routing emails.

  1. Go to Send -> Receiving and Create a Route.

  2. Expression Type -> Match Recipient

    • Enter admin@figgy.foo
  3. Enable Forward and fill in your personal address. For me that'd be my normal gmail address.

  4. Set priority to 50 so you have space to add future routes before or after this route.

  5. Add a simple description like "send to gmail" and Create the Route.

At the free tier you can only have 5 routes total. I only use the following:

  1. Match no-reply@figgy.foo, Store and Notify and Stop processing.
  2. Match family@figgy.foo, forward that email to multiple family members.
    • Useful for events and family plans.
  3. Match Kindle@figgy.foo, forward to my custom Amazon provided kindle email address for sending epubs/pdfs.
    • much friendlier address than what they make for you.
  4. A catch all final route that just forwards to my personal address.

Number 4 is where most of the magic and utility of setting all this up happens. I can give out unlimited custom email addresses and I'll know who sent them by the address. That is, if I give out businessName@fig.systems I can later use that in gmail to filter, block, or search for anything related to that business. I can even see who sold my info if I start getting spam from that address.