DEV Community

Cover image for Send email from your own domain: DKIM, SPF and DMARC, reply-to, and scheduled reminders
CloudHike Team
CloudHike Team

Posted on

Send email from your own domain: DKIM, SPF and DMARC, reply-to, and scheduled reminders

This is week 6 of Build with CloudHike, a weekly series where we build a small, real-world app with an AI coding agent and let CloudHike handle the backend.

New here? Week 1 built a referral waitlist, week 2 moved slow AI work into background jobs, week 3 built a file-sharing app with presigned uploads, week 4 connected every major AI editor to one project, and week 5 built a members-only SaaS with verified sign-up, password reset, and GitHub and Google sign-in. Each post stands on its own, so you can start right here.

Week 1 already sent a "you're #N" confirmation from a CloudHike address. That's the easy case: one API call, no SMTP, and mail goes out. The moment those messages are part of a real product, the list gets longer. The From line should be your domain, not <project>@cloudhike.dev. Replies should land in an inbox you actually read. A reminder should go out later, and you should be able to cancel it if the person already finished. And when something bounces, you need a log that shows what happened, without storing the body of every message.

Usually that list means an ESP account, a DNS worksheet, and a second provider if you also want to schedule sends. This week your agent deploys CloudHike Email over MCP, you verify a subdomain under Email → Domains, and you build the rest with copy-paste prompts.

Every endpoint, field and setting below comes from the live Email docs, MCP docs and email acceptable use policy.

What we're building

A Next.js app called receipt-desk that sends transactional mail from a domain you own:

  • A receipt form: type an address and send a short "thanks for your order" email from server code
  • A first send from CloudHike.dev, with replyTo set, so you can test before any DNS work
  • A verified subdomain such as mail.yourdomain.com, with the DKIM, SPF and DMARC records the Email page lists
  • The same receipt, from your domain, using from, fromName and replyTo
  • A scheduled reminder with scheduledAt (an ISO time up to 7 days ahead), which answers 202 and an id you can cancel
  • The Logs and Overview tabs, so you can see who each message went to and what happened
  • An optional hook-up to Auth: once the domain is verified, verification and password-reset emails can come from an address on it

Here's how it maps to CloudHike:

  • Email (EMAIL_API_URL, EMAIL_API_KEY). A plain HTTP API for transactional sends, scheduled sends and cancellations. Keep the key on your server: anyone with it can send as your project
  • Your own domain, verified under Email → Domains, or, if you leave from out, mail from <project>@cloudhike.dev
  • No SMTP to configure, and no message bodies stored (a scheduled message is held only until it is sent or cancelled)

What you need

  • A CloudHike account. Every new account gets $10 in free credits (eligible accounts, once per inbox, valid for 90 days), plus an extra $5 with the code TUBEGURUJI5, and no card is needed. The Free plan allows 2 projects, 1 custom email domain, 100 emails per 24 hours and 3,000 a month, which is plenty for this.
  • Cursor or Claude Code (Codex, VS Code, Windsurf and Gemini CLI work too; see week 4).
  • Node.js, for a Next.js app.
  • A domain you own or are authorized to use, so you can add the DNS records the Email page shows.
  • An inbox you can read, to receive the test receipt and reminder, and a reply-to address you actually check.

Step 1: Connect CloudHike to your agent (once)

In the CloudHike dashboard, open Connect MCP in the sidebar (https://cloudhike.dev/dashboard/coding-agent), pick your editor and click Copy with key. That creates your workspace API key the first time and gives you a snippet with the key already filled in. The server is remote (Streamable HTTP), so there's nothing to install.

Claude Code

claude mcp add --transport http --scope user cloudhike https://cloudhike.dev/api/mcp \
  --header "Authorization: Bearer icu_your_api_key"
Enter fullscreen mode Exit fullscreen mode

Run /mcp inside Claude Code to check that it's connected.

Cursor (~/.cursor/mcp.json)

{
  "mcpServers": {
    "cloudhike": {
      "url": "https://cloudhike.dev/api/mcp",
      "headers": {
        "Authorization": "Bearer icu_your_api_key"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Open Cursor Settings → MCP and look for the green dot. Snippets for Codex, VS Code, Windsurf, Gemini CLI and Claude Desktop are in the MCP docs.

Treat the key like a password: keep it in your home folder, not the repo. Revoke on the Connect MCP page disconnects every editor at once.

Step 2: Scaffold the app

npx create-next-app@latest receipt-desk
cd receipt-desk
Enter fullscreen mode Exit fullscreen mode

Open the folder in Cursor, or run claude in it.

Step 3: Let the agent deploy Email

Paste:

Use the cloudhike MCP tools to set up the backend for this app. It's a Next.js app that sends transactional email: a receipt and a scheduled reminder.

Create a CloudHike project called "receipt-desk". Deploy email and wait until it's ready. Put the .env into .env.local, make sure it's git-ignored, and don't show me any secret values. Then call get_docs for "email" and summarise the send API, the request fields, how scheduledAt and cancel work, and how to send from a verified domain. Don't write app code yet. Tell me which services are running and which variable names are in .env.local.

Behind the scenes that's create_project, deploy_services with email, wait_for_services, get_environment written straight into .env.local, and get_docs for the Email page as Markdown. You should end up with EMAIL_API_URL and EMAIL_API_KEY.

The Email service is for transactional mail only, and deploying it means you agree to CloudHike's email acceptable use policy. The docs also describe ticking the box on the Email card and clicking Deploy. If the agent says Email couldn't be deployed, do that in the dashboard and ask the agent to fetch the .env again.

What those two values are for, straight from the docs:

  • EMAIL_API_URL: the base address of your project's email API. Server only.
  • EMAIL_API_KEY: sent as the x-api-key header. Server only. Anyone with it can send as your project.

Step 4: Send a first receipt from cloudhike.dev

You can send before any DNS work. Left out, from is <project>@cloudhike.dev. The docs say to set replyTo when you send from that shared domain, so replies have somewhere to go.

Here's the send call from the docs, which we'll wrap in a small form:

const res = await fetch(`${process.env.EMAIL_API_URL}/send`, {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": process.env.EMAIL_API_KEY!,
  },
  body: JSON.stringify({
    to: "customer@example.com",
    subject: "Your receipt",
    html: "<p>Thanks for your order.</p>",
    text: "Thanks for your order.",
    from: "receipts@acme.com",   // optional, needs acme.com verified
    fromName: "Acme",
    replyTo: "support@acme.com",
  }),
});
const { results } = await res.json(); // [{ to, id, status }]
Enter fullscreen mode Exit fullscreen mode

For this step, leave from out so the project address is used. Paste:

Using only what the email page from get_docs describes, build a receipt form in this Next.js app, with every CloudHike call in server code:

  • lib/email.ts: a sendEmail helper that POSTs to {EMAIL_API_URL}/send with the header x-api-key set to EMAIL_API_KEY and content-type application/json. It accepts to, subject, html, text, and optional from, fromName, replyTo and scheduledAt. It returns the JSON body and the HTTP status. Do not log or return EMAIL_API_KEY.
  • A page at / with to, subject and a short message, plus a reply-to field that defaults to a REPLY_TO env variable (add REPLY_TO to .env.local, and the name only to .env.example). Posting the form calls POST /api/send-receipt, which uses sendEmail. For now, do not send a from address, so mail goes from the project's CloudHike.dev address. Always set replyTo. Send both html and text. If the API answers 429, read the Retry-After header, do not retry in a loop, and show that the send was rate limited.
  • After a send, show the id and status from results (the docs describe results as [{ to, id, status }]). Keep EMAIL_API_URL and EMAIL_API_KEY out of any client bundle: no NEXT_PUBLIC_ prefix.

Try it with an inbox you can read. You should see the mail come from <project>@cloudhike.dev, and a reply should go to the address you set as replyTo. Then open the project, click the Email card, and check the Logs tab: it shows who each message went to and what happened. Message bodies are never stored.

The fields you're allowed to send, still from the docs:

  • to: one address or an array. Each recipient counts as one email.
  • subject: up to 200 characters, no line breaks.
  • html and text: send either or both, up to 256 KB each.
  • from: any address on one of the project's verified domains. Left out, mail goes from <project>@cloudhike.dev.
  • fromName: display name, 1 to 60 characters, with no address or link in it.
  • replyTo: where replies go. Set it when sending from cloudhike.dev.
  • scheduledAt: ISO time up to 7 days ahead. Answers 202. We'll use this in Step 6.

Step 5: Verify a subdomain under Email → Domains

Sending from mail.yourdomain.com (or any domain you add) is a dashboard and DNS step, not an MCP tool. A subdomain such as mail.acme.com keeps email reputation apart from your main domain, which is what the docs recommend.

Open the project, open the Email page, go to Domains and add your domain. Then:

  1. Add the records it lists at your DNS provider: three DKIM CNAME records (required), an MX and an SPF TXT record on bounce.<domain>, and a DMARC TXT record (recommended). Use the values on that page, not a guess.
  2. Click Verify now, or wait: CloudHike checks every few minutes for 72 hours. Each record shows whether it was found.
  3. Once the domain shows Verified, you can send with from set to any address on it, such as receipts@mail.yourdomain.com if you verified mail.yourdomain.com.

Free accounts can add 1 domain, Pro accounts 5 and Scale accounts 20, across all projects. If the DKIM records are removed later, the domain is marked failed and sending from it stops until you verify it again. Removing the records or the domain also stops scheduled email from that domain.

Add the address you'll send from to .env.local as FROM_EMAIL (and the name only to .env.example), then paste:

The domain is now verified. Update /api/send-receipt so it sends from FROM_EMAIL when that env variable is set, and sets fromName to a short display name with no address or link in it (for example "Receipt Desk", at most 60 characters). Keep replyTo. If FROM_EMAIL is missing, leave from out and still set replyTo, as in Step 4. Don't put FROM_EMAIL in the browser bundle.

Send another receipt to yourself. The From line should now be your domain. Replies still go to replyTo.

Step 6: Schedule a reminder, then cancel it

scheduledAt is an ISO time up to 7 days ahead. The send call answers 202, and the usual results array still gives you an id. To cancel that send: POST {EMAIL_API_URL}/emails/<id>/cancel. A scheduled message's body is held only until it is sent or cancelled; everything else still follows the rule that bodies aren't stored.

Paste:

Add a reminder flow using only the scheduledAt and cancel behaviour from the email docs:

  • On the same form, a second action: "Schedule reminder". It calls POST /api/schedule-reminder, which uses sendEmail with scheduledAt set to an ISO time the user picks, no more than 7 days ahead. Subject and body should be a short transactional reminder about the same order, with html and text, from/fromName as in Step 5, and replyTo set. Show the HTTP status (the docs say a scheduled send answers 202) and the id from results.
  • A cancel field: paste that id and post to POST /api/cancel-reminder, which calls POST {EMAIL_API_URL}/emails//cancel from server code, with the same x-api-key header as /send. Show whatever status the API returns. Never accept an id from the client and then cancel it from browser code.

Try it in two passes. First, schedule a reminder a few minutes ahead, wait, and see it arrive. Second, schedule another and cancel it before that time. Then check the Logs tab again for both ids.

Step 7: Read the delivery logs, and stay transactional

You don't need a logs API for this. On the Email page:

  • The Logs tab shows who each message went to and what happened. CloudHike keeps the sender, recipient, subject and delivery status so you can see them there. It does not store message bodies, except that a scheduled message is held until it is sent or cancelled.
  • The Overview tab charts each day's delivered, bounced and failed mail, and your bounce and complaint rates.

A few rules from the docs and the policy are worth treating as part of the build, not as fine print:

  • Transactional only. Sign-in links, password resets, receipts, alerts, invoices, and notifications someone turned on are in bounds. Marketing, newsletters, promotions or any bulk mail are not, even to people who opted in.
  • Each recipient counts as one email. to can be one address or an array, but Free allows 3 recipients per request (50 on Pro).
  • Over a limit, the API answers 429 with a Retry-After header. That's why the form in Step 4 doesn't retry in a loop.
  • Addresses that bounce for good or report spam are never mailed again.
  • Sending pauses for a project whose mail bounces 3% or is reported as spam 0.3% of the time over 7 days. A pause holds email for every project on the account, including new ones, until support reviews it.
  • A monthly spend cap under Settings limits what you can spend. On Pro, emails sent above the monthly allowance are charged from your credits every hour; refused, failed and cancelled messages are free.

Step 8 (optional): Send Auth emails from the same domain

If you already have Auth in this project from week 5, you don't need a second email provider for verification and password-reset mail. On the Auth page's Emails tab you can change the sender name, send from an address on a domain you have verified under Email → Domains, set a reply-to address, and edit the wording of those emails with a live preview and a test send.

That's the same verified domain as Step 5. Auth still sends those messages itself; you don't call /send for them.

Step 9: Ship it

On Vercel (or any host), add EMAIL_API_URL, EMAIL_API_KEY, REPLY_TO and FROM_EMAIL in the project settings. In the CloudHike dashboard, Environment → Copy as .env gives you the whole file. Then:

  • Keep the API key on the server. Don't prefix it with NEXT_PUBLIC_, don't ship it to a mobile app, and don't commit .env.local.
  • Leave the DNS records in place. If the DKIM records disappear, the domain is marked failed and sending from it stops, including scheduled mail, until you verify it again.
  • Stay transactional in production the same way you did in development. The acceptable use policy you agreed to when Email was deployed still applies on your own domain.
  • Set a monthly spend cap under Settings if you want a hard ceiling, or an alert amount if you only want a warning.
  • Testing without touching production. Every project can add a development environment from the switcher under the project name, with its own services, keys and .env. MCP tools take an environment argument for it.

What CloudHike handled

Look back at what you didn't do: you didn't open an ESP account, write raw DKIM records from memory, stand up SMTP, or store a copy of every message body. One MCP connection and one Email page gave you:

  • transactional sends as a plain HTTP API, from <project>@cloudhike.dev with no setup,
  • your own domain, verified with the DKIM, SPF and DMARC records listed under Email → Domains,
  • from, fromName and replyTo, so the message looks like it comes from you and replies land in your inbox,
  • scheduledAt reminders up to 7 days ahead, with a cancel call for an id,
  • Logs and Overview, with bodies left out of storage,
  • a hard line that this is transactional mail only, with bounce and complaint pauses that protect the shared sending reputation.

On cost: Free includes 100 emails per 24 hours, 3,000 a month, 10 a minute, 3 recipients per request and 1 custom domain. Pro has no daily or monthly cap, 300 emails a minute, 50 recipients per request and 5 custom domains; Scale has 1,000 emails a minute and 20 custom domains. On Pro and Scale, 3,000 emails a month per project are included, then $0.40 per 1,000 (each recipient counts as one). Everything comes out of one credit balance. If you outgrow Free, Pro is $10/month with $10 of usage credits included every month and 10 projects, and Scale is $29.99/month with unlimited projects. The details are on the plans and billing page.

Your turn

Run the prompts in order: Step 3 to deploy, Step 4 to send from cloudhike.dev, the Step 5 DNS clicks, then Steps 6 and 7 for reminders and logs. Then try to break it: send a receipt to yourself and hit reply, schedule a reminder and cancel it, remove FROM_EMAIL temporarily and confirm mail falls back to the CloudHike.dev address, open Logs and Overview after each send.

👉 Start free at cloudhike.dev. You get $10 in credits at signup, plus $5 more with code TUBEGURUJI5, no card required.

Next week: let your agent explore your data safely. We'll use the database explorer, list_tables, describe_table and read-only query_database, look at Pro's execute_sql with editor approval and the audit log, and go over nightly backups and restore. Follow along so you don't miss it.

If you try this one, tell me in the comments whether the first send from your own domain landed, and whether scheduling or cancel was the step that needed a second prompt. I read every comment.

Top comments (0)