Skip to main content

Appendix B. Generating SMTP Commands from RFC 822 Header Fields

This appendix provides guidance on generating SMTP envelope commands (MAIL FROM and RCPT TO) from RFC 5322 (formerly RFC 822) message header fields.

Envelope vs. Header Addresses

SMTP Envelope: The addresses used in MAIL FROM and RCPT TO commands Message Headers: The addresses appearing in From:, To:, Cc:, Bcc: fields

Important: Envelope and header addresses may differ!

Generating MAIL FROM

The reverse-path (MAIL FROM) should typically be derived from:

  1. Return-Path header (if present and trusted)
  2. Sender header (if present)
  3. From header (fallback)

For bounce messages, use null reverse-path: MAIL FROM:<>

Generating RCPT TO

Recipients should be collected from:

  • To: header
  • Cc: header
  • Bcc: header (then remove from message)
  • Resent-To:, Resent-Cc:, Resent-Bcc: (for resent messages)

Example

Message Headers:

SMTP Commands:

MAIL FROM:``<[email protected]>``
RCPT TO:``<[email protected]>``
RCPT TO:``<[email protected]>``
RCPT TO:``<[email protected]>``

Transmitted Message Headers (BCC removed):

From: [email protected]
To: [email protected]
Cc: [email protected]
Subject: Meeting tomorrow

Special Cases

Distribution Lists

When sending to a mailing list, the RCPT TO may differ from visible To:/Cc: headers:

MAIL FROM:``<[email protected]>``
RCPT TO:``<[email protected]>``
RCPT TO:``<[email protected]>``
...

Headers show:
To: [email protected]

Forwarding

When forwarding, original envelope may be different from headers:

Original: alice → bob
Forward: bob → charlie

MAIL FROM:``<[email protected]>`` (original sender)
RCPT TO:``<[email protected]>`` (new recipient)