How Email Works: SMTP, MX Records & Webhooks Explained
This article takes a look at how email works in practice when being sent from your sender's servers via DNS MX records and SMTP daemons.
Infrastructure Engineering
Email is one of the simplest and most long-standing protocols used within the global internet. While emails seem fast in web applications (such as receiving a verification code or notification), there are many complex steps that occur between the sender and recipient with regards to networking, DNS lookups and cryptography.
As either a software developer setting up transactional notifications, system admin setting up mail exchanges or just a TempMail user looking to secure your mailbox from marketing spam, knowing how an email works will help give you valuable insight into how data is transmitted over the internet and why emails can take time to arrive.
1. The Full Journey of an Email
When you click submit on an email form (such as registering or requesting a one-off verification password (OTP)), your browser will initiate a chain of events across several servers:
- MIME Creation: The email headers, HTML body, text alternative & attachments are created according to RFC 5322 (Internet Message Format) and RFC 2045 (MIME).
- Sending to MTA: The payload is passed to an MTA (Message Transfer Agent) such as Postfix, SendGrid, Amazon SES or Mailgun. The application will use ports 587/465 via SMTP.
- DNS & MX Lookup: The MTA will separate the recipient domain from the email (i.e. [email protected]). The MTA will perform a DNS (Domain Name System) lookup to find the MX (Mail Exchange) record for that domain.
- TCP & TLS: An TCP connection will be opened with the recipient server (from the MX record) on port 25. The sender will start the STARTTLS handshake.
- Recipient Validation & Spam Check: The recipient will validate SPF, DKIM & DMARC alignment, check the IP Reputation, perform anti-virus heuristics.
- Receipt & Web Push: The payload will be parsed by the recipient daemon. The HTML will be cleaned up and the email pushed to the users current open browser session via WebSockets.
2. Understanding DNS & MX Records
The DNS (Domain Name System) is often known as the phonebook of the internet. Whereas regular web traffic will point a domain to a web server (via A (IPv4) or AAAA (IPv6) records), email will use MX records.
An MX record will point to the hostname(s) which will accept mail for a domain. Each record will have a priority number:
;; Sample DNS MX Record Configuration
example.com. 3600 IN MX 10 mx1.inbound-cluster.com.
example.com. 3600 IN MX 20 mx2.inbound-cluster.com.
The sender will attempt to connect to the MX host with the priority number first (Highest priority is 10 in this example). If the main host doesn’t respond (due to maintenance or congestion), the sender will attempt to connect to the next hosts (20). If no MX Records exist, or there is an issue with the DNS propagation, no emails will be able to be sent to that domain.
3. SMTP (Simple Mail Transfer Protocol)
SMTP is a text protocol used to send email, defined by RFC 5321. This is a conversation between a client (sender) and a server (daemon). Below is an example:
S: 220 mx.temp-mail.services ESMTP Service Ready
C: EHLO mailout.sender-network.com
S: 250-mx.temp-mail.services greets mailout.sender-network.com
S: 250-STARTTLS
S: 250 OK
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
[... Cryptographic TLS Handshake Negotiated...]
C: MAIL FROM:
S: 250 2.1.0 Sender OK
C: RCPT TO:
S: 250 2.1.5 Recipient OK
C: DATA
S: 354 Start mail input; end with .
C: From: Sender App
C: To: [email protected]
C: Subject: Your Verification Code: 492018
C: Date: Sun, 01 Nov 2026 14:00:00 +0000
C:
C: Welcome to Sender App! Your confirmation code is 492018.
C:.
S: 250 2.0.0 OK: message queued 10928472
C: QUIT
S: 221 2.0.0 Bye. All commands will have a response code. A successful command will return a 250 OK. If the server is busy or the email address doesn’t exist, different response codes will be returned.
4. Email Validation: SPF, DKIM & DMARC
The original SMTP standard had no validation in place (1982). However, today we have three validation protocols to keep us safe on the internet:
- SPF (Sender Policy Framework): This is a TXT record put on the sender’s domain. It contains a list of IP addresses allowed to send emails. Any emails sent from IP addresses outside of that list will be rejected.
- DKIM (DomainKeys Identified Mail): A digital signature will be added to the header by the senders mail server. The receiving mail server will look up the sender’s key in the DNS. It will check that the body hasn’t been changed.
- DMARC (Domain-based Message Authentication, Reporting & Conformance): This is a policy to tell the recipient what to do if SPF or DKIM fail. This could be to reject (p=reject) or quarantine (p=quarantine) the email. This prevents phishing & spoofing.
5. Webhook
Traditional email services store your emails on disk. They will wait for you to connect to them using either IMAP or POP3. TempMail has been designed to send your emails directly to your web browser.
- Webhook (Incoming): Once the SMTP transaction has completed, the recipient daemon will parse the MIME data and create a JSON payload. A webhook will be made internally via HTTPS.
- HTML Cleaning: Any HTML in the body will be cleaned up by parsing through a sanitizer. This will remove any malicious JavaScript, tracking & harmful CSS.
- Client Polling (Live): If you have your inbox open, the client will poll for new emails every few seconds. Our 10 Minute Mail tool will have an auto-expire timer.
6. Why Emails Take Time To Arrive & How To Fix It
If your email is taking minutes to arrive, there are typically 3 reasons:
- MTA Greylisting: Many mail servers will greylist the sender. This means they will return a 451 Temporary Failure. Good senders will retry after 1-5 minutes. If your verification email is taking time, leave your inbox open and click the timer extension button.
- Outbound Queue Congestion: Large commercial services will batch their transactional emails. This can cause the outbound queues to cause a delay of 2-5 minutes.
- Blocked Domains: Some sites will have filters to stop generic disposable domains. In this case, switch to our Google authenticated Gmail Temp Mailbox.