How does Postfix MTA receive mail from the outside world? please describe the routing from the outside email requesting to be sent until it is delivered to the user's mailbox.
When Postfix MTA (Mail Transfer Agent) receives an email from the outside world, the process of receiving and delivering that email to the user's mailbox involves multiple steps. Here’s a detailed description of how the email travels from an external sender to the user’s mailbox in a Postfix-based system:
Postfix MTA 如何接收來自外界的郵件?請描述從請求發送的外部電子郵件到發送到使用者郵箱的路由。
When someone sends an email to a domain (e.g., user@example.com), the sender's MTA first queries the Domain Name System (DNS) to find the MX (Mail Exchange) records for the recipient’s domain (e.g., example.com).
The MX record tells the sender’s MTA which server is responsible for receiving emails for that domain.
After getting the MX record, the sender's MTA tries to establish a connection with the Postfix server specified by the MX record.
2. SMTP Connection Establishment
The sender’s MTA opens an SMTP (Simple Mail Transfer Protocol) connection to Postfix via port 25 (the standard SMTP port) or port 587 for secure submission.
Postfix listens on these ports for incoming mail.
3. SMTP Handshake and Security (TLS/SSL)
During the SMTP handshake, Postfix and the sender’s MTA exchange greetings and determine the protocols and encryption (such as TLS) they both support.
If encryption is supported and required, the connection is secured using TLS.
4. Sender and Recipient Validation
The sending MTA provides the sender's address and the recipient's address.
Postfix performs several checks during this process:
SPF (Sender Policy Framework) and DKIM (DomainKeys Identified Mail) checks: These help verify the legitimacy of the sender's domain.
Recipient Address Check: Postfix verifies if the recipient’s email address exists in its system.
Postfix uses its configuration (such as relay_domains and mydestination parameters) to determine if it should accept the email for the given recipient.
5. Queueing the Email
Once the email is accepted, Postfix temporarily stores the email in its incoming queue (usually /var/spool/postfix/incoming).
Postfix processes emails in queues using different daemons (such as cleanup and qmgr).
6. Mail Processing and Content Filtering
Postfix may use external tools for content filtering (e.g., SpamAssassin, Amavis) or antivirus scanning. These tools scan the email for spam, malware, or policy violations.
If the email passes the filtering checks, it moves to the next stage.
7. Local Delivery or Relay
Postfix checks if the recipient's email is for local delivery or needs to be relayed to another MTA:
Local Delivery: If the recipient’s domain matches the local domain (configured in mydestination), Postfix delivers the email to the local mailbox using an internal delivery agent like local or an external agent such as Dovecot or Cyrus.
Relay to Another Server: If the recipient is not local, Postfix forwards the email to the appropriate MTA based on the recipient’s domain.
8. Delivery to User's Mailbox
For local delivery, Postfix either delivers the email to a mailbox file or passes it to a local Mail Delivery Agent (MDA) such as Dovecot (if IMAP/POP3 is used) or another MDA.
If using Maildir format, the email is delivered into the user's specific folder (e.g., /home/user/Maildir/).
If using mbox format, the email is appended to the single mailbox file.
9. User Accesses the Email
The user can now access their email via an email client (e.g., Thunderbird, Outlook) using either IMAP or POP3 protocols.
These protocols are handled by an IMAP/POP3 server such as Dovecot or Courier that interacts with the email store (Maildir or mbox).
Overview of Key Components:
DNS: Provides MX records to direct email traffic.
Postfix: Receives and processes the email.
Content Filters: Optional spam and virus filters.
MDA (Mail Delivery Agent): Delivers the email to the user’s mailbox (e.g., Dovecot, Procmail).
Mailbox: Stores the user’s email (Maildir or mbox format).
User Access: The user accesses the email via IMAP/POP3 clients.
Example Flow:
Sender sends an email to user@example.com.
Sender’s MTA checks the MX record for example.com and finds Postfix’s IP.
SMTP connection is established, and Postfix receives the email.
Postfix processes the email, performing security checks and filtering.
Postfix delivers the email to user@example.com in the mailbox.
User retrieves the email using IMAP/POP3 via an email client.
This outlines the entire process from the email being sent from the outside to its delivery to the user's mailbox in a Postfix environment.