Build Your Own Custom Domain Email on AWS with Gmail
Get email at your own domain for about 50 cents a month. Amazon SES receives it, a Lambda forwards it to Gmail, and you reply as your domain. All in Terraform.
Series: AWS Domain Email (1 article)
- 1Build Your Own Custom Domain Email on AWS with Gmail This article
Cloud engineer and AWS Community Builder, turning hands on projects into content at stratajen.net
Build Your Own Custom Domain Email on AWS with Gmail
Here's how to get an email address at your own domain without paying for a mailbox. I built mine on AWS. Mail comes in through Amazon SES and lands in my Gmail. I reply from Gmail and it goes out as my domain address. On the free tier it costs about 50 cents a month. That's just the Route 53 hosted zone, and new account credits can cover even that. Everything is in Terraform.
Why build it this way
- It's cheap. Under a dollar a month, even past free tier.
- You keep Gmail. Same inbox, same apps, same search.
- You own it. No mailbox subscription to cancel or lose.
- You learn a lot. SES, Lambda, S3, Route 53, IAM, and Terraform, all in one small project.
- It's real. You use it every day, so it's a portfolio project you can actually talk about.
How it works
Getting mail:
- Someone emails
YOUR_MAILBOX@YOUR_DOMAIN.
- Your domain's MX record sends it to SES. MX stands for Mail Exchange. It's the DNS record that says which server takes email for your domain.
- An SES receipt rule matches your address and scans it for spam and viruses.
- SES saves the raw email to S3.
- SES runs a small Lambda function.
- The Lambda changes the From line to your domain address, keeps the real sender in Reply-To, and sends it to your Gmail.
Why change From? SES won't send mail pretending to be from someone else's domain. Reply-To makes sure hitting reply still goes to the right person.
Sending mail:
- You write in Gmail and pick your domain address in the From dropdown.
- Gmail sends it through SES using an SMTP login Terraform creates.
- SES signs it with DKIM. DKIM stands for DomainKeys Identified Mail. It's a digital signature that proves the email came from your domain and nobody changed it.
- The other person sees your domain address, not your Gmail.
What you're building:
Piece | What it does |
|---|---|
Route 53 records | MX, DKIM, SPF, and DMARC for your domain |
SES identities | Your domain, plus your Gmail while you're in the sandbox |
S3 bucket | Holds raw incoming mail, deleted after 90 days |
Lambda | Forwards each email to Gmail |
SES receipt rule | Sends mail for your address to S3, then the Lambda |
IAM user | The SMTP login Gmail uses to send as your domain |
The cons
It's not a real mail provider. You need to know what you are building.
Sending takes two extra steps. Out of the box, this only receives. Your domain address can't send anything until you connect it to Gmail in Step 3. Until then, replies go out from your Gmail. After that, you're still in the SES sandbox. The sandbox only delivers to addresses you've verified. Forwarding to your own Gmail works because you verify it. Emailing a recruiter, a client, or anyone else bounces. So does replying to them. You have to request production access in Step 4. It's usually approved in about a day, but it can be denied.
Gmail is your mailbox. There's no separate inbox, webmail, or IMAP. Lose that Gmail and you lose your domain email too.
You can't sign in with it. Your domain address isn't a Google account. It's an alias Gmail sends as. "Sign in with Google" logs you in as your Gmail, not your domain. Same with Microsoft and Apple. Regular email and password signups work fine, and the codes get forwarded to you. If you really want "Sign in with Google" on your domain address, you can make a separate Google account using an existing email. Just know that's a second account with its own password.
Everything says "via YOUR_BRAND." The Lambda has to rewrite From. So Gmail filters that sort by sender won't work the way you'd expect. Reply-To still points to the real person.
The sender's signature gets stripped. Forwarding changes the message, so their DKIM signature won't match anymore. Spam filtering is mostly up to the SES scan.
40 MB limit. SES caps messages at 40 MB in and out. Big attachments can fail.
One active rule set per region. If your account already receives email with SES, add your rule to that set.
Only some regions receive email. us-east-1, us-west-2, and eu-west-1 work. Check before you pick.
A long lived access key. Gmail's "Send mail as" needs a username and password. That means an IAM user with a static key. You can lock it down to your one address, but rotate it now and then.
Best practices for that key:
- Rotate it every 90 days. Run
terraform apply -replace="aws_iam_access_key.smtp[0]", then paste the new password into Gmail.
- Only store it in Gmail. Not in a notes app, a text file, or a password you reuse.
- Use it for one thing. This key is only for Gmail sending. Never use it for the AWS CLI or anything else.
- Check when it was last used. In IAM, open the SMTP user and look at "Last used." If it was used when you weren't sending, delete it.
- Lock down the account around it. Turn on MFA for your root user and your admin user. Don't use the root user day to day.
- If it leaks, delete it first, ask questions later. Delete the key in IAM, then run
terraform applyto make a new one.
You're the help desk. If mail stops, it's on you. You'll be reading Lambda logs and DNS records.
It's more work than a paid mailbox, but it's a good learning experience. If you just want email, pay for a mailbox. This is for people who want to learn how email works and want a real project to show for it.
Security risks to know
This setup works, but it has gaps. Here's what to watch for and what you can do about it now. Part 2 fixes these.
- Reporting spam can hurt your own domain. Forwarded mail comes from your domain through your SES account. If you hit "Report spam" in Gmail, that counts as a complaint against you. Too many and AWS can pause your sending. Delete junk instead, or set up a Gmail filter on
[SPAM?].
- A leaked SMTP key lets someone send as you. It only works for your one address, but that's exactly what a scammer wants. If it ever leaks, delete the key in IAM and run
terraform applyto make a new one.
- Your state file isn't encrypted. It sits in your project folder with the SMTP password inside. Anyone who gets that folder gets the password. Keep it off shared drives and out of GitHub.
- Raw emails sit in S3 for 90 days. Anyone with S3 access to your AWS account can read them. Turn on MFA for your AWS account, and lower
retention_daysif you don't need them that long.
- People can fake email from your domain until you tighten DMARC.
p=noneonly reports. Move top=quarantineonce your reports look clean, like in Step 4.
- Mail can arrive unencrypted.
tls_policy = "Optional"accepts mail from servers that don't use TLS. Change it to"Require"if you're okay with some senders bouncing.
- Someone could flood your address. Every email costs a little and runs the Lambda. The budget alert from Before you start makes sure a surprise bill can't sneak up on you.
What it costs
On the free tier, about 50 cents a month. Past free tier, about 60 to 75 cents. Most of that is the Route 53 hosted zone. Your domain is a separate yearly cost. If you already have a personal website on your own domain in Route 53, like a portfolio site or your Cloud Resume Challenge, you're already paying for both. This just adds email.
These numbers assume a few hundred small emails a month.
Service | AWS price | Free tier | Past free tier |
|---|---|---|---|
Route 53 hosted zone | $0.50 per zone per month | No free tier | $0.50 |
SES receiving | $0.10 per 1,000 emails, plus $0.09 per 1,000 incoming 256 KB chunks | Covered by new account credits | About $0.10 |
SES sending | $0.10 per 1,000 emails, plus $0.12 per GB of attachments | Covered by new account credits | Pennies |
Lambda | $0.20 per million requests, plus compute | Always free: 1 million requests and 400,000 GB seconds a month | $0 |
S3 | Storage plus requests | Covered by new account credits | Pennies |
CloudWatch Logs | Per GB ingested | Covered by new account credits | Pennies |
Total | | About $0.50, or $0 while credits last | About $0.60 to $0.75 |
Compared to paying for email
Option | Monthly cost | The catch |
|---|---|---|
Cloudflare Email Routing | $0 | Receive only. You can't send as your domain without another service. Your DNS has to move to Cloudflare. |
This build | About $0.10 to $0.25 on top of the hosted zone | You set it up and fix it yourself |
iCloud+ | $0.99 for the 50 GB plan | You use iCloud Mail, not Gmail. Best if you're already on Apple. |
Zoho Mail Lite | $1 per user for 5 GB, or $1.25 for 10 GB. Billed yearly only. | You live in Zoho's app, not Gmail |
Zoho Workplace Standard | $4 per user, billed monthly | Adds 30 GB of mail and shared file storage |
Fastmail Individual | $5 billed yearly, $6 month to month | One user. Great app, but it's not Gmail. |
Proton Mail Essentials | $6.99 per user, billed monthly | Privacy focused, up to 3 custom domains |
Google Workspace Business Starter | $7 per user billed yearly, $8.40 month to month | A real Google account. "Sign in with Google" works. |
Microsoft 365 Business Basic | $7 per user billed yearly, $8.40 month to month | Outlook, plus web versions of the Office apps |
Zoho lists a free plan, but it's only offered in some regions. When I signed up, I had to pay.
If your domain already lives in Route 53, you're paying for the hosted zone either way. So this build only adds pennies. The only thing cheaper is free forwarding like Cloudflare, and that can't send. iCloud+ comes close if you're already on Apple. Everything else costs more, and none of them let you keep Gmail.
Prices as of November 2026 from Zoho , Apple , Fastmail via Dupple , Proton via Capterra , Google Workspace via Email Vendor Selection , Microsoft 365 via O365HQ , and Cloudflare Email Routing via The Admin Bar . Prices change, so check before you pick.
How the free tier works now
New accounts get up to $200 in credits. When you sign up, you pick a free plan or a paid plan. The free plan lasts 6 months. On the paid plan, your credits still come off your bill until they run out or expire after 12 months. SES doesn't have its own free email count anymore. It uses those credits. Lambda still has an amount that's always free, no matter how old your account is. Route 53 is never free.
Before you start
What you need
- An AWS account you can use from the AWS CLI with admin access
- A domain with a public hosted zone in Route 53, in that same account
- A Gmail account to forward to
- Terraform 1.10 or newer (
terraform version)
- The AWS CLI, logged into the right account
New to AWS? AWS Skill Builder has free training. Start with Cloud Practitioner Essentials so things like IAM, S3, and Lambda make sense before you build.
New to Terraform? Watch this video first . You don't need to be an expert. Just know what
init , plan , and apply do before you run them on your own domain.Fill in your values
Every placeholder in this post is one of these. Fill in the table first and keep it open.
Placeholder | What it is | Example | Yours |
|---|---|---|---|
YOUR_DOMAIN | Your domain, with a Route 53 hosted zone | example.com | |
YOUR_MAILBOX | The part before the @ | hello | |
YOUR_GMAIL | Where mail gets forwarded | someone@gmail.com | |
YOUR_REGION | An SES region that receives email | us-east-1 | |
YOUR_BRAND | Shows in Gmail as "Sender via YOUR_BRAND" | MyBrand | |
YOUR_NAME | Your name in Gmail's Send mail as | Your Name | |
Your address will be
YOUR_MAILBOX@YOUR_DOMAIN .Pick a region that receives email. Not every region does. us-east-1, us-west-2, and eu-west-1 all work. Check the SES receiving endpoints for the current list.
Set up a budget alert
Do this before you build anything. AWS won't warn you if something starts costing money. A budget will. It doesn't stop anything, it just emails you before the bill does.
- In the AWS console, search for Budgets.
- Click Create budget, then Use a template, then Monthly cost budget.
- Set an amount you'd be surprised to see, like $10.
- Enter the email you want alerts sent to.
- Click Create budget.
Now you'll get an email when you get close to that amount, and another if AWS thinks you'll go over.
Step 1: Get the code
git clone https://github.com/JenMagruder/aws-domain-email.gitcd aws-domain-emailcp terraform.tfvars.example terraform.tfvarsOn Windows PowerShell, use
copy instead of cp .Open
terraform.tfvars and put in your values from the table above. You don't need to change anything else.File | What it does |
|---|---|
main.tf | The whole build: DNS, SES, the S3 bucket, the Lambda, the receipt rule, and the SMTP user |
variables.tf | The settings you can change |
terraform.tfvars.example | A template for your own values |
versions.tf | Terraform version and providers |
outputs.tf | Prints your SMTP login after you apply |
lambda/forwarder.py | Forwards each email to Gmail |
.gitignore | Keeps your secrets and your real values off GitHub |
What the main parts do
- DKIM, SPF, and DMARC. These keep your mail out of spam. DKIM proves the mail came from your domain. SPF says SES is allowed to send for you. DMARC tells other servers what to do if those checks fail. It starts at
p=none, so you just get reports.
- The bucket policy. Only SES can write to the bucket, only from your account, and only from your rule.
- The Lambda. It drops anything that failed the virus scan, rewrites From to your domain, keeps the real sender in Reply-To, tags flagged spam with
[SPAM?], and sends it to Gmail. It can only read theinbound/folder and only send as your address.
- The receipt rule. It saves to S3 first, then runs the Lambda. SES doesn't wait on the Lambda, so a slow run never fails someone's email.
- The SMTP user. It can only send as your address. That's it.
Keep your secrets off GitHub
Your state file will have your SMTP password in it, in plain text.
terraform.tfvars has your real domain and Gmail. The repo's .gitignore already keeps both off GitHub. If you push your own copy, run git status first and make sure neither one shows up.⚠️ Never paste the SMTP password anywhere, including the README, commit messages, or screenshots.
Step 2: Preflight checks and apply
Preflight checks
Do these before you apply. Each one catches something that's a pain to fix later.
1. No MX record yet. If your domain already gets email somewhere, this would take it over.
# Mac or Linuxdig MX YOUR_DOMAIN +short
# Windows PowerShellResolve-DnsName YOUR_DOMAIN -Type MXNothing back, or just an SOA line, means you're good.
2. No active receipt rule set. Only one can be active per region.
aws ses describe-active-receipt-rule-set --region YOUR_REGIONNo output means you're good.
3. Right account. The hosted zone has to be in the account you deploy to.
aws route53 list-hosted-zones-by-name --dns-name YOUR_DOMAIN --query "HostedZones[0].Name" --output textIt should print your domain with a dot at the end.
4. Nothing blocks IAM users. If your account is in an AWS Organization with an SCP that denies
iam:CreateUser , set create_smtp_user = false . You'll still get mail. You just won't be able to send from Gmail.Apply
terraform initterraform planterraform applyRead the plan before you type
yes . It should say 30 to add, 0 to change, 0 to destroy. If anything says change or destroy, stop and figure out why. It takes a minute or two, mostly waiting on DNS.Step 3: Verify, test, and connect Gmail
Verify your Gmail
Check
YOUR_GMAIL for an email from Amazon Web Services and click the link. Check spam if it's not there. The Lambda can't forward to you until you do this.Check that your domain verified
aws sesv2 get-email-identity --email-identity YOUR_DOMAIN --region YOUR_REGION --query "{dkim:DkimAttributes.Status,mailfrom:MailFromAttributes.MailFromDomainStatus}"Both should say
SUCCESS . If they say PENDING , give DNS up to an hour.Send a test
From any other email account, send something to
YOUR_MAILBOX@YOUR_DOMAIN . In about a minute it should show up in your Gmail as "Their Name via YOUR_BRAND."Didn't show up? Check the Lambda logs:
aws logs tail /aws/lambda/YOUR_DOMAIN_WITH_DASHES-mail-forwarder --since 30m --region YOUR_REGIONYOUR_DOMAIN_WITH_DASHES is your domain with dashes instead of dots. So example.com becomes example-com .Get your SMTP login
terraform output smtp_usernameterraform output -raw smtp_passwordThe username is fine to see. The password is a real secret. Copy it straight into Gmail and don't paste it anywhere else.
Set up Gmail "Send mail as"
Do this on a computer. The Gmail phone app doesn't have these settings.
- In Gmail, click the gear, then See all settings.
- Open the Accounts and Import tab.
- Under Send mail as, click Add another email address.
- Fill in the first screen, then click Next Step:
Field | Value |
|---|---|
Name | YOUR_NAME |
Email address | YOUR_MAILBOX@YOUR_DOMAIN |
Treat as an alias | Checked |
- Fill in the SMTP screen, then click Add Account:
Field | Value |
|---|---|
SMTP Server | email-smtp.YOUR_REGION.amazonaws.com |
Port | 587 |
Username | The smtp_username output, without quotes |
Password | The smtp_password output |
Security | Secured connection using TLS |
- Gmail emails a confirmation code to your domain address. Your forwarder sends it right back to Gmail. Click the link or enter the code.
- Back on Accounts and Import, under When replying to a message, pick Reply from the same address the message was sent to.
Now your domain address shows up in the From dropdown. When you reply to mail sent to it, Gmail uses it automatically.
If Gmail says the login failed, it's almost always the password not copying right. Run the output command again and copy the whole thing.
Step 4: Get out of the SES sandbox
Until you do this, your domain address can only send to addresses you've verified in SES. Getting mail works fine. Sending to anyone else bounces, even a reply.
In the SES console for
YOUR_REGION , go to Account dashboard, then Request production access.Field | What to put |
|---|---|
Mail type | Transactional |
Website URL | https://YOUR_DOMAIN |
Use case | See the sample below |
Here's a sample. Change it so it's true for you:
Personal business email for one address, YOUR_MAILBOX@YOUR_DOMAIN. I send one to one replies to clients and contacts from Gmail through SES SMTP. Low volume, under 50 emails a day. The domain is verified with DKIM, a custom MAIL FROM domain, SPF, and DMARC. Bounces and complaints go to the same mailbox. I don't send marketing or bulk email.
AWS usually answers in about a day. Be specific and honest. Vague requests get denied.
Test sending
Once you're approved, send from your domain address to an account that isn't yours, like a friend's. Have them open the email and look at the original message or headers. You want DKIM: PASS and SPF: PASS for your domain.
Tighten DMARC later
After a couple weeks, look at the DMARC reports that come to your address. If everything real is passing, change the DMARC record in
main.tf to:v=DMARC1; p=quarantine; rua=mailto:YOUR_MAILBOX@YOUR_DOMAIN; fo=1That tells other servers to send anything that fails your checks to spam. It stops people from faking emails from your domain.
Gotchas I hit along the way
Problem | What happened | Fix |
|---|---|---|
Terraform upgrade didn't stick | Chocolatey needs an admin window, and a failed try left a stale shim | Run as admin, then choco install terraform --force -y |
If you take one thing from this post: always read the plan before you type yes. It tells you exactly what's about to change. If anything says change or destroy and you didn't expect it, stop.
If you build this, let me know how it goes.
Coming soon: Part 2. I'll show you how to take this project further and fix the security risks above.
Series: AWS Domain Email (1 article)
- 1Build Your Own Custom Domain Email on AWS with Gmail This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article