What Does a Mail Server Receive When an Email Is Sent?

After the sender presses Send, the outgoing mail system has a message to pass on. The Internet Engineering Task Force's RFC 5321 sets out three steps for that handoff under the Simple Mail Transfer Protocol (SMTP): give the reverse-path, give the recipient addresses, then transfer the message content. The reverse-path normally carries a return address, but it can be null, meaning no address is supplied. The receiving server takes responsibility when it sends a success reply after the data. That reply comes from a mail system; it does not say that the recipient has read the email.

Blue network cables curve between charcoal racks in a server room.

Which sender does the outgoing server identify first?

The sending server opens a connection. The receiving server answers with a greeting. RFC 5321 calls the sending system the SMTP client and the receiving system the SMTP server, names for their roles in this exchange. The client normally identifies its own host during the greeting exchange. That identification names the system on the connection; the reverse-path for the particular email comes later, when the mail transaction begins.

The SMTP client sends a MAIL command to start the transaction. RFC 5321 calls its return information the reverse-path. When it contains an address, that address is used to report delivery failures. A non-delivery notification is sent with a null reverse-path. The receiving server sets aside the details of any previous transaction as it starts a new one. If the receiving server accepts the MAIL command, it has accepted the start of the transaction and the return information. No recipient has been specified for that transaction yet.

The Internet Engineering Task Force describes the distinction in RFC 5321: "A mail object contains an envelope and content." The reverse-path belongs to the envelope, which carries return and recipient information outside the message content and may include optional transport information. The From field in the message belongs to the content. The server receives the reverse-path before it receives any of the written message, including its From field.

The Two Directions on the Connection
SMTP client:
Sends commands towards the receiving server
SMTP server:
Sends replies back towards the sending client

The request and reply travel on the same connection in opposite directions.

How does a recipient address cross the connection?

The sending server supplies a recipient with the RCPT command. Each RCPT command identifies a single recipient. RFC 5321 calls that destination the forward-path, normally a mailbox address. If the receiving server accepts the command, it stores that address. The reply concerns the recipient just named, while the text that goes with the address is still on the sending side.

For a message intended for several recipients, the sending server can repeat the RCPT step. The receiving server can therefore answer differently for different recipients in the same transaction. Suppose a note is meant for a scheduling mailbox and a workshop mailbox. If the receiving server accepts the scheduling address and rejects the workshop address, the reply about the scheduling address does not settle what happens to the workshop copy. The same note is involved in both requests, but the requests are about different addresses.

RFC 5321 separates an address from the mailbox it names. An address identifies a person or a place to deposit the mail; the mailbox is the place where the mail can be deposited. An accepted recipient command records an address for this transaction. It is an earlier event than the receiving server's acceptance of the message itself.

What crosses the connection as message data?

The sending server issues DATA after giving the envelope information. The receiving server returns an intermediate reply if it is ready to receive the message data. The sending server then transmits the header and the body. The header is the collection of named fields above the body in the message format. RFC 5321 lists Date, Subject, To, Cc and From among the fields carried in the mail data.

In the hypothetical workshop note, a subject such as Bench layout would travel with the message data, alongside the header's address fields and the note itself. The receiving server would already have the scheduling address in the envelope. The Subject field gives the receiving account something to recognise in the message. It plays no part in the earlier exchange that established the scheduling address as a destination for this transfer.

Envelope and Message Content
Transport envelope
Reverse-path: normally a return address, sometimes null
Recipient address supplied for delivery
Passed ahead of the data
Message content
From field in the message header
To and Cc fields in the message header
Sent as a header and a body

The receiving server also needs a way to distinguish the end of the message from a line inside it. In the basic exchange, SMTP uses a line containing only a full stop as its end-of-data signal. RFC 5321 specifies a separate handling rule so a full stop in the original text can survive without being mistaken for the signal. After the signal, the receiving server can act on the stored recipients and data and return to sending replies.

When does the receiving server take responsibility?

The receiving server can acknowledge a return address and a destination before it has any of the message. It can also signal readiness for the data before it knows the outcome of the transfer. The point that changes who is responsible is the success reply after the end of the data. Under RFC 5321, the server sending that reply must deliver the message or properly report a failure to do so. If delivery fails after acceptance and the return address is present, the standard directs the failure notification back to the address from the envelope return path or its recorded equivalent.

The same success code, 250, can appear in reply to MAIL, to RCPT and after the end of the data. Its position in the exchange tells the sending server what has succeeded. A temporary error after the data leaves responsibility with the sending server, which can put the message back in its queue for another attempt. That is distinct from the receiving server accepting the message and subsequently sending a failure notice.

What Reaches the Inbox
  1. Send: The sender's mail software passes the message to the outgoing system, which starts the SMTP handoff with a reverse-path that can be null
  2. Acceptance: The receiving server confirms success after the mail data
  3. Final delivery: The delivery system can deposit the message in the receiving account's message store

The success reply reaches the sending server across the same connection that carried the data. It is about that particular handoff. A relay, a system that receives mail and sends it further, can give the same kind of acceptance as a final delivery system. In a relay exchange there is still a trip ahead, even though the previous sending server has received a success reply.

At final delivery, the delivery server inserts a Return-Path field into the mail data. RFC 5321 specifies that this field preserves the return information supplied with MAIL. That is how a piece of the transport envelope can leave a record in the delivered message. If the reverse-path contains an address, the Return-Path field records where a delivery failure can be reported. The From field remains part of the message header supplied with the content.

The recipient's mail software appears at the other end of the delivery route. RFC 5321 describes a delivery system that can pass the message to that software or deposit it in a message store, a place the software accesses later. The observable result on the receiving account, in the latter case, is the deposited message in the store the account's mail software reads.

Frequently Asked Questions

Where is a relay hop recorded in an email?

An SMTP relay acts as the receiver on its incoming connection and as the sender on a subsequent connection. RFC 5321 requires the receiving SMTP server to add a trace entry to the message: a Received field. Each new Received field goes at the start of the message content, above the earlier entries.

Can recipients share a single transfer of the message data?

RFC 5321 encourages a single copy of the mail data for recipients at the same destination or intermediate relay host. In that case the receiving host gets the individual recipient addresses and a shared copy of the content. The recommendation applies to the common receiving host for that transfer; it does not imply that a recipient list represents just one mailbox.

Can the same SMTP connection carry another mail transaction?

An SMTP client can start another mail transaction on the same connection once a message has been transmitted. The client can also request that the connection be closed instead. The lifetime of a connection is therefore distinct from the lifetime of a transaction for a particular message.

What does the number in an SMTP reply tell the sending system?

RFC 5321 assigns the first digit of an SMTP reply code to the broad outcome, such as completion, a request for more information or a failure. The second digit gives an indication of the kind of response, and the third supplies a finer distinction. The numeric code is for software to act on, while any accompanying text is usually intended for people.

What happens if a sender abandons an SMTP transaction?

The SMTP reset command, RSET, tells the receiving server to abort the current mail transaction and discard the sender address, recipients and message data it has stored for it. The reset leaves the connection open. The sending server can abandon that particular transfer without ending the session between the two systems.

Sources

  • Internet Engineering Task Force: Simple Mail Transfer Protocol