Blog

How Email Works: A Developer’s Guide

Learn how email moves from your app through DNS and SMTP, how SPF, DKIM, and DMARC work, and how to troubleshoot delivery.

Email moves through a chain of servers. Your app creates a message and hands it to a sending service. That service looks up the recipient’s mail server, transfers the message, and the receiving server decides whether to accept it, reject it, or put it in spam.

The exact path varies, but the main parts are the same: message content, DNS, SMTP, and checks that help receiving servers assess who sent the message.

1. Your app creates a message

An email has headers and a body. Headers carry information such as the sender, recipient, subject, and reply address. The body contains the message itself.

Email can include both plain text and HTML. A message with both is sent as a MIME multipart message, so email clients can choose which version to display. Attachments and inline images are also described using MIME.

A typical message might have headers like these:

text
From: alerts@example.com
To: person@example.net
Subject: Your receipt
Reply-To: support@example.com

The visible From address is not proof of who sent the message. That is why receiving servers also check authentication records and message signatures.

2. Your app hands the message to a sending service

Your app can submit email using an email API or an SMTP server. With an API, your server sends a request over HTTPS. With SMTP, your server connects to a mail server and submits the message using the SMTP protocol.

In either case, keep credentials on your server. Do not put an API key or SMTP password in browser code or a mobile app. Anyone who can inspect that code could copy the credential and send mail through your account.

An email API handles the connection to the wider mail system for you. For example, the SendPanda API accepts messages from your app and sends them onward. The sending guide covers API sends, idempotency, and message lookup.

3. DNS helps find the recipient’s mail server

When the sending service needs to deliver a message to person@example.net, it looks up the domain’s MX records. MX records name the servers that receive mail for that domain. Their numbers set priority: a lower number is preferred.

You can inspect a domain’s MX records from a terminal:

sh
dig MX example.com

A record has this general shape:

text
example.com. 3600 IN MX 10 mail.example.com.

Here, 10 is the priority and mail.example.com. is the mail server hostname. This is an example of the record format, not a server you should use for your own domain. The hostname must point to a real mail server configured to receive mail for that domain.

If you are setting up a domain to send mail, follow your email provider’s DNS instructions. Sending and receiving are separate jobs: adding a sending-domain record does not automatically make your domain able to receive email. See the domain setup guide for the records used with SendPanda.

4. SMTP transfers the message

After finding the recipient’s mail server, the sending service connects to it using SMTP. The servers exchange commands and responses. The sender identifies itself, gives the envelope sender and recipient, then transfers the message content.

The SMTP envelope is separate from the message headers. For example, the envelope recipient controls where the server tries to deliver the message. The To header is what the recipient sees in their email client. They often match, but they do not have to.

The receiving server can accept or reject the message. If it accepts the message, that means it took responsibility for processing it. It does not guarantee the email will appear in the recipient’s inbox. The server may still classify it as spam, quarantine it, or apply other filters.

5. Receiving servers check authentication

Receiving servers use DNS records and message data to assess whether a message is authorized and whether its identity is trustworthy.

  • SPF says which sending servers are allowed to send mail for a domain.
  • DKIM adds a cryptographic signature to a message. The receiving server checks the signature against a public key in DNS.
  • DMARC tells receiving servers how to handle mail that fails authentication checks and can send reports to the domain owner.

To look up records, run commands such as:

sh
dig TXT example.com
dig TXT _dmarc.example.com

An SPF record is a TXT record that starts with v=spf1. For example, this is a syntactically valid record using a documentation-only IP address:

text
v=spf1 ip4:192.0.2.10 -all

It authorizes that IP address and says other senders should fail SPF. Do not publish this as-is: 192.0.2.10 is not your sending service. Use the SPF instructions from your provider, and keep one SPF record for each domain. DKIM records are generated for your domain by your email provider. Publish the exact selector and key it gives you. The SPF, DKIM, and DMARC guide explains how the checks fit together.

6. Delivery can succeed, fail, or be deferred

A receiving server can accept a message, reject it, or ask the sender to try again later. Temporary errors can lead to retries. A permanent rejection can produce a bounce, which reports that delivery failed.

Your app should not treat “the API request succeeded” as “the person read the email.” A successful request means the sending service accepted the request. Delivery status and recipient actions are separate events. Check your provider’s message status and handle delivery events if your app needs to react to bounces or other outcomes. See the delivery guide.

For transactional mail, also think about retries in your own app. If a request times out, you may not know whether the provider accepted it. Retrying without protection can send a duplicate. Use an idempotency key tied to the event, such as a specific password-reset request or receipt. The idempotency guide shows how.

A practical checklist

When email from your app does not arrive, check the path in order:

  1. Confirm your server can reach the email API or SMTP service and has the right credentials.
  2. Check the API response or SMTP response. An accepted request is not proof of inbox placement.
  3. Confirm the sending domain’s required DNS records are published and verified.
  4. Check message status, bounce details, and webhook events.
  5. Ask the recipient to check spam or quarantine, then confirm the address is correct.

Email is a sequence of handoffs, not a single action. Your app submits a message, DNS helps route it, SMTP carries it between servers, and the recipient’s provider makes the final decision about where it goes. Knowing which step failed makes delivery problems much easier to diagnose.

Send your first email today.

Start free and connect your domain in a few minutes.