Recent from talks
Nothing was collected or created yet.
Message delivery agent
View on WikipediaA message delivery agent (MDA), or mail delivery agent, is a computer software component that is responsible for the delivery of e-mail messages to a local recipient's mailbox.[1] It is also called a local delivery agent (LDA).
Within the Internet mail architecture, local message delivery is achieved through a process of handling messages from the message transfer agent, and storing mail into the recipient's environment (typically a mailbox).
Spam filtering usually occurs at the MDA under modern email architectures.[2]
Implementation
[edit]Many mail handling software products bundle multiple message delivery agents with the message transfer agent component, providing for site customization of the specifics of mail delivery to a user.
Unix
[edit]On Unix-like systems, procmail and maildrop are the most popular MDAs. The Local Mail Transfer Protocol (LMTP) is a protocol that is frequently implemented by network-aware MDAs.[citation needed]
Invocation
[edit]The mail delivery agent is generally not started from the command line, but is usually invoked by mail delivery subsystems, such as a mail transport agent, or a mail retrieval agent.
Unix-like
[edit]- Cyrus IMAP - A mail server suite that includes a mail delivery agent
- dovecot - A mail server suite that includes a mail delivery agent
- fetchmail - Primarily a Mail retrieval agent (MRA)
- getmail - simpler, more secure, modern fetchmail alternative
- fdm — modern replacement for both fetchmail and procmail from the author of tmux
- maildrop or courier-maildrop - traditional procmail replacement, part of Courier Mail Server, but can also be used with other mail servers
- procmail - old, but still used
- bin/mail, the MDA part of Sendmail - Sendmail is one of the oldest email packages
- Sieve mail filtering language - a standardised mail filtering language; also, a modern replacement for procmail from the GNU Mailutils package
See also
[edit]- Message transfer agent (MTA)
- Mail retrieval agent (MRA)
- Message submission agent (MSA)
- Message user agent (MUA) a.k.a. email client
- E-mail agent (infrastructure) (MxA)
References
[edit]- ^ RFC 5598, Internet Mail Architecture, D. Crocker (July 2009)
- ^ Levine, John (June 10, 2025). "SMTP headers in DATA block?". mailsec (Mailing list). Internet Engineering Task Force. Retrieved June 10, 2025.
All my experience says that the right place to do mail filtering is the MDA. It has all of the information and has all the options about what to do with the mail. There are MUAs that try to do filtering but that's mostly an historical artifact from a long time ago when MDA filtering didn't happen.
Message delivery agent
View on Grokipediamail utility.[4] Some MTAs, including Postfix and Sendmail, can double as MDAs by appending messages directly to spool files when handling local deliveries.[5] These agents have evolved alongside email standards since the early days of SMTP, adapting to modern needs like scalability and integration with cloud-based mail services.[6]
Definition and Role
Definition of MDA
A message delivery agent (MDA), also known as a mail delivery agent, is a software component in the Internet mail architecture responsible for the final delivery of email messages to a recipient's local storage, such as a user mailbox on the recipient's system. This process marks the transfer of responsibility from the message handling service (MHS) to the recipient's environment, completing the delivery phase by depositing the message into a designated storage location.[1] Key characteristics of an MDA include handling post-transfer processing after the message has been received from a message transfer agent (MTA), often via protocols designed for local transport such as the Local Mail Transfer Protocol (LMTP). LMTP facilitates efficient delivery to systems that do not manage their own queues, providing per-recipient status replies to ensure accurate handling without requiring the MDA to queue messages. Additionally, MDAs enforce policies, perform filtering, and ensure secure deposition of messages into standardized formats, supporting the integrity and accessibility of the stored content.[1][7] Typical outputs of an MDA involve appending messages to local files or database entries without further network transmission, such as storing in the mbox format where messages are sequentially added to a single file per mailbox, or in the Maildir format which uses individual files for each message to enhance reliability and concurrent access. These local storage mechanisms allow subsequent retrieval by message user agents (MUAs) through protocols like IMAP or POP3. In the broader email pipeline, the MDA finalizes the journey of a message after inter-system transfer by the MTA.[8][1]Distinction from MTA and MUA
A Message Delivery Agent (MDA) serves as the final component in the email delivery chain, distinct from both a Mail Transfer Agent (MTA) and a Mail User Agent (MUA) in its specialized role of local mailbox placement. While an MTA handles the routing and transfer of messages across networks using protocols like SMTP, performing one application-level hop at a time to move mail closer to the recipient, an MDA focuses solely on the terminal delivery step without engaging in inter-server routing.[9][10] In contrast, an MUA operates on behalf of users for composing, submitting, or retrieving messages, providing the interface for email creation and consumption but not participating in server-side transfer or delivery processes.[11] The distinctions are evident in the overall email workflow, where a message originates from the author's MUA, which submits it via a Mail Submission Agent (MSA) to an MTA for relay through potentially multiple MTAs until it reaches the recipient's domain. The recipient's MTA then hands off the message to the MDA, which deposits it into the recipient's message store or mailbox, from where the recipient's MUA retrieves it for viewing.[12] This sequence—MUA (sender) → MSA/MTA → MTA(s) → MDA → MUA (recipient)—highlights the MDA's position as the bridge from network transfer to local storage, without user interaction or content modification beyond policy enforcement.[10]| Component | Primary Role | Key Protocols/Interactions | User Involvement |
|---|---|---|---|
| MTA | Routes and relays messages between servers for network transit. | SMTP for hop-by-hop transfer. | None; server-side only.[9] |
| MDA | Performs final local delivery to a recipient's mailbox or store. | Interfaces with MTAs and local file systems or databases. | None; automated server-side delivery.[10] |
| MUA | Enables users to compose, send, receive, and manage emails. | POP/IMAP for retrieval; SMTP for submission via MSA. | Direct; client software with UI.[11] |
Historical Development
Early Unix implementations
The earliest message delivery agents (MDAs) emerged in the 1970s as part of the foundational Unix mail systems, initially designed for simple local message handling among users on the same machine. The 'mail' command, introduced in the first edition of Unix in November 1971, served as a primitive MDA, primarily appending incoming messages to a shared mailbox file, typically located at /usr/spool/mail or equivalent paths.[15] This basic functionality allowed senders to pipe messages directly to recipients' files without remote networking capabilities, reflecting the time-sharing environment of early Unix where inter-user communication was limited to the local system.[15] A key milestone was the 'binmail' program, the binary implementation of /bin/mail, which acted as the first dedicated simple MDA by appending messages to the recipient's mbox file in a format that included a Unix-style "From" envelope line followed by the message body.[16] Over the late 1970s and into the 1980s, these systems evolved to incorporate user ID (UID) and group ID (GID) handling for secure delivery; binmail, often running setuid root, would switch its effective UID to that of the recipient to write to the protected mailbox, preventing unauthorized access while maintaining file ownership integrity.[17] This adaptation addressed initial security gaps in multi-user environments, though it introduced complexities in privilege management. With the advent of more sophisticated mail transfer agents like sendmail in 1979, /bin/mail continued as the default local MDA, invoked to finalize delivery after transport.[18] Early Unix MDAs adhered to emerging standards for message formats, particularly following the publication of RFC 822 in 1982, which defined the syntax for ARPA Internet text messages and influenced local storage practices by emphasizing structured headers and body separation in file-based mailboxes.[19] However, these implementations had significant limitations: they offered no message filtering or sorting, relying solely on append-only delivery to a single mbox file per user, which simplified design but restricted flexibility.[20] Moreover, vulnerabilities to concurrent access plagued early versions; race conditions in binmail allowed attackers to manipulate temporary files or locks during delivery, potentially enabling arbitrary file writes or denial of service by failing to remove lock files. These issues stemmed from the lack of atomic file operations in the underlying filesystem, highlighting the trade-offs in early Unix's minimalist approach to mail handling.[21]Advancements in the 1990s and beyond
In the 1990s, message delivery agents evolved significantly from their early Unix roots, incorporating advanced filtering and reliable storage mechanisms to handle growing email volumes and complexity. Procmail, first released in December 1990, introduced powerful rule-based filtering capabilities, allowing users to sort, forward, and process incoming messages based on custom conditions such as headers, content, or sender details. This marked a shift toward programmable MDAs that went beyond simple local delivery, enabling automated workflows for personal and server environments. Concurrently, the introduction of the Maildir format in 1996 by qmail provided an atomic delivery method, storing each message as a separate file in a directory structure to avoid locking issues and improve reliability, particularly in networked filesystems like NFS.[22][23][24] Standardization efforts further refined MDA operations during this period. The Local Mail Transfer Protocol (LMTP), defined in RFC 2033 in October 1996, facilitated reliable handoff from MTAs to MDAs by adapting SMTP principles for local delivery without queuing, reducing errors in high-volume scenarios and enabling better integration with modular mail systems. By 2001, RFC 2822 updated the Internet Message Format, clarifying header structures and encoding rules that impacted local delivery processes, ensuring consistency in how MDAs parsed and stored messages across diverse implementations. These protocols addressed limitations in earlier systems, promoting interoperability and robustness.[7][25] Entering the 2000s, MDAs gained enhanced integration with IMAP servers and support for multi-tenant environments. Dovecot, released in July 2002, incorporated a local delivery agent that seamlessly interfaced with its IMAP/POP3 components, supporting virtual domains to manage mailboxes across multiple hosted domains on a single server without namespace conflicts.[26][27] This era also saw MDAs like procmail and successors add hooks for spam filtering, integrating with tools such as SpamAssassin—introduced in 2001 and widely adopted by the mid-2000s—for content-based analysis and scoring during delivery, helping mitigate the spam surge that escalated post-2000.[28] In modern trends, MDAs have adapted to containerized and secure deployment models. Compatibility with containerization platforms like Docker emerged prominently in the 2010s, with official images for Dovecot's LDA enabling isolated, scalable mail delivery in microservices architectures, facilitating easier management in cloud environments. Security enhancements include TLS support for local transport protocols like LMTP, as implemented in Postfix since the early 2000s, encrypting intra-system handoffs to protect against eavesdropping in shared hosting setups and aligning with broader email security standards.[29][30]Core Functionality
Local delivery mechanisms
Local delivery agents (MDAs) receive messages from message transfer agents (MTAs) primarily through standard input (stdin) or via the Local Mail Transfer Protocol (LMTP) over a socket, as defined in RFC 2033, which facilitates delivery to local mailbox systems without the queuing semantics of SMTP.[31] Upon reception, the MDA parses the message headers to identify the recipient and any delivery instructions, then appends the message to the appropriate local storage format while ensuring atomicity to prevent corruption.[6] This process typically involves creating a temporary file for the message content before renaming it into the final location, minimizing the risk of partial writes during delivery.[32] The two predominant local storage formats supported by MDAs are mbox and Maildir, each with distinct structures and trade-offs in performance and reliability. In the mbox format, all messages for a mailbox are stored sequentially in a single flat file, where each message begins with a "From " line and ends with a blank line, offering simplicity for basic implementations but requiring careful synchronization to handle concurrent access.[33] To manage concurrency in mbox, MDAs employ locking mechanisms such as dot-locking, which creates a .lock file in the same directory as the mailbox to signal exclusive access, often combined with file-level locks like flock for robustness across filesystems.[34] Conversely, the Maildir format stores each message as an individual file within a directory structure featuring subdirectories for new, current, and temporary messages (tmp, new, cur), enabling lock-free delivery since operations on separate files avoid conflicts and support high concurrency without additional synchronization.[35] While mbox provides efficient sequential access for small mailboxes due to its compact nature, Maildir enhances reliability in multi-process environments by reducing the impact of single-file corruption and simplifying recovery, though it incurs higher disk usage from metadata in filenames.[36] For undeliverable messages, MDAs generate bounce notifications, also known as delivery status notifications (DSNs), formatted according to RFC 3464, which specifies an extensible MIME structure for reporting failure reasons, and RFC 3463 for enhanced status codes indicating issues like permanent or transient errors.[37][38] Quota management involves checking storage limits before delivery, rejecting messages that exceed user-defined thresholds and triggering a bounce with a 5xx SMTP code for permanent failure, while temporary issues such as full disks or permission denials result in 4xx codes prompting the MTA to retry later.[6] Security in local delivery emphasizes minimizing privileges, with MDAs typically executing as the non-root recipient user to limit potential damage from malformed messages or exploits, as seen in implementations like Postfix's local(8) daemon.[39] Before writing to the mailbox, the MDA verifies the recipient's ownership and read/write permissions on the target directory or file, preventing unauthorized access and ensuring compliance with filesystem security models.[6]Filtering and sorting capabilities
Message delivery agents (MDAs) enhance email organization by implementing rule-based filtering and sorting systems, which evaluate incoming messages against predefined conditions and execute corresponding actions. These systems typically consist of condition-action pairs that inspect message attributes such as sender addresses in the "From" header, keywords in the "Subject" line, textual content within the body, or even message size thresholds. If a condition matches, the MDA can perform actions like forwarding the message to another recipient, filing it into a specific mailbox folder for sorting, discarding it outright, or piping it to an external script for further processing.[40] Representative capabilities include integration with spam detection tools, where MDAs invoke external scanners to assign spam scores based on content analysis; for instance, an MDA might route high-scoring messages to a quarantine folder or prepend warning headers. Auto-reply generation is another common feature, allowing automated responses to specific senders or during user absences, often through hooks that trigger reply scripts. Mailing list handling can be achieved by rules that detect list-specific headers (e.g., "List-Id") and direct messages to dedicated folders, streamlining subscription management.[41] A key standard for these capabilities is the Sieve language, defined in RFC 5228 (2008), which provides a scriptable framework for server-side email filtering at the point of final delivery. Sieve scripts compile into bytecode for efficient execution by MDAs, supporting tests on headers, body matches, and envelope information, with actions like "fileinto" for sorting into folders or "redirect" for forwarding. This contrasts with client-side rules in mail user agents (MUAs), as Sieve operates non-interactively on the server without requiring user intervention during processing.[40] Limitations of MDA filtering include its server-side nature, which precludes real-time adjustments based on user input and focuses solely on batch processing at delivery time, potentially leading to rigid handling of dynamic scenarios like evolving spam patterns without external updates.Common Implementations
Procmail
Procmail is a mail delivery agent (MDA) originally developed by Stephen R. van den Berg and first released on December 7, 1990, as version 1.00.[42] It gained widespread adoption in Unix-like systems for its robust capabilities in filtering and processing incoming email messages before final delivery to user mailboxes.[43] As one of the earliest dedicated mail filtering programs, Procmail processes mail handed off from a mail transfer agent (MTA), applying user-defined rules to sort, forward, or otherwise manage messages efficiently.[44] The core of Procmail's functionality revolves around its recipe-based configuration system, defined in a user's ~/.procmailrc file, which allows for conditional processing of emails using flags, regular expressions, and actions.[45] Recipes enable forwarding messages to other addresses, filing them into specific folders, or integrating with spam detection tools like DSPAM through piping to external programs.[46] Procmail supports delivery to traditional mbox formats as well as the more modern Maildir structure, providing flexibility for different mail storage needs.[47] Among its strengths, Procmail's extensibility stands out, as recipes can invoke external scripts or commands via pipes, allowing seamless integration with custom tools or utilities for advanced processing.[48] It has historically served as the default MDA for many Unix MTAs, including Sendmail, particularly in distributions like Red Hat and its derivatives, due to its resource efficiency and reliability in handling mail spooling.[49] This made it a staple for server environments requiring automated email management without heavy overhead. After a long period of inactivity, Procmail's last stable release is version 3.24, issued on March 2, 2022, with maintenance resuming thereafter.[50] Its reliance on executing user-defined scripts introduces potential security risks, such as remote code execution vulnerabilities if recipes are misconfigured or exploited, as evidenced by historical CVEs like CVE-2002-2034 that allow bypassing filters.[51] Despite these concerns, it remains in use in legacy systems where compatibility with existing configurations is prioritized.[52]Dovecot Local Delivery Agent
The Dovecot Local Delivery Agent (LDA) is a component of the Dovecot open-source IMAP and POP3 server, initially released in July 2002 by developer Timo Sirainen. It functions as a mail delivery agent that receives messages from a Mail Transfer Agent (MTA) and stores them in user mailboxes while maintaining Dovecot's index files for efficient access. The LDA integrates seamlessly within Dovecot environments, supporting delivery through Sieve scripts via the Pigeonhole plugin or other plugins, enabling automated processing of incoming mail.[53][54] Key features of the Dovecot LDA include native support for the Sieve language as defined in RFC 5228, which allows users to define filtering rules for incoming messages. It handles virtual user mapping, permitting delivery to non-system users through configuration backends like LDAP or SQL databases. Deliveries are performed atomically to formats such as Maildir or Dovecot's proprietary sdbox, ensuring message integrity and preventing partial writes during storage. Additionally, the LDA supports mailbox indexing during delivery, which accelerates subsequent IMAP or POP3 access by keeping metadata synchronized.[55][56][57] The Dovecot LDA excels in high-performance scenarios for large-scale deployments, leveraging Dovecot's efficient indexing and low-overhead design to handle high volumes of mail without significant resource demands. It incorporates built-in authentication mechanisms, drawing from Dovecot's passdb and userdb systems, and enforces quotas through the dedicated quota plugin to prevent mailbox overfills. These capabilities make it suitable for enterprise mail servers requiring reliability and scalability.[58][59] In typical usage, the Dovecot LDA pairs with MTAs such as Postfix or Exim, where it is invoked via transport maps or aliases to route local deliveries. This integration facilitates modern features like push notifications in IMAP setups, as the LDA's indexing ensures real-time updates for client synchronization.[60][61]Maildrop and others
Maildrop serves as the primary message delivery agent within the Courier mail server suite, initially released in May 2000. It emphasizes secure local delivery to Maildir-format mailboxes, incorporating quota enforcement to prevent disk overuse and basic filtering via user-defined scripts in a .mailfilter file.[62] This design supports integration with the broader Courier ecosystem, including authentication libraries for LDAP and SQL backends, while maintaining a lightweight footprint suitable for small-scale deployments.[63] Other notable MDAs include the delivery component of Binc IMAP, a C++-based server from the early 2000s optimized for virtual domains and Maildir storage, which handles local delivery for IMAP users with a focus on performance and security.[64] LMTP-specific tools, such as proxy-based implementations like those configurable in Postfix for LMTP handoff, enable efficient delivery in segmented environments by treating LMTP as a local transport protocol to avoid SMTP's error-handling complexities. Legacy options persist in systems like MMDF's "deliver" daemon, developed in the 1980s at the University of Delaware, which manages multichannel delivery queues for early Unix mail routing.[65] These alternatives highlight lightweight MDAs tailored for resource-constrained settings, such as embedded systems requiring minimal overhead or non-Unix platforms via ports like Cygwin, where tools like maildrop can operate under POSIX emulation without full Unix dependencies.[66] Recent trends show a decline in standalone MDAs, as modern MTAs like Postfix integrate native local delivery transports, reducing the need for separate agents in favor of unified configurations.Configuration and Usage
Invocation methods
Message delivery agents (MDAs) are typically invoked by mail transfer agents (MTAs) to handle the final delivery of messages to local recipients. Command-line invocation is a common method, where the MTA pipes the message content to the MDA's standard input while passing the recipient as a command-line argument. For instance, in Unix-like systems, an MTA might use an alias entry like| /usr/bin/[procmail](/page/Procmail) -d username to trigger delivery, with the -d flag specifying the recipient to ensure proper user context. This approach allows the MDA to process the message in a non-interactive, batch-oriented manner, reading from stdin until end-of-file.[67][68]
Protocol-based invocation provides an alternative for more structured handoffs, particularly using the Local Mail Transfer Protocol (LMTP) over TCP or Unix domain sockets. LMTP enables the MTA to connect to a listening MDA server, transferring the message and receiving per-recipient delivery status responses, which is advantageous for multi-recipient deliveries without relying on single exit codes from command-line processes. This method is specified in RFC 2033 and is often used for local inter-process communication rather than wide-area networking. Stdin piping remains prevalent in simpler setups, but LMTP offers enhanced feedback mechanisms, such as support for ESMTP extensions.[69]
Environment variables play a crucial role in configuring delivery paths and user context during invocation. Variables like LOGNAME (set to the recipient's username) and HOME (the recipient's home directory) are preset by the invoking MTA to guide mailbox locations and file permissions, ensuring the MDA operates under the correct user environment. For example, in Procmail, these variables help determine default delivery to ~/Mail or system spool files if not overridden. Signal handling is also important for graceful operations; common signals like SIGTERM trigger message requeuing, while SIGINT or SIGHUP may bounce undelivered mail to prevent data loss during interruptions.[67][68]
Best practices emphasize security and reliability in invocation. MDAs should run in non-daemon mode—invoked per-message by the MTA rather than as persistent processes—to minimize attack surfaces and privileges, often executing as the recipient user via setuid mechanisms. Logging to syslog is recommended for diagnostics, with MDAs directing output to the mail facility for centralized monitoring and auditing of delivery events. Tools like Procmail exemplify these practices by supporting logging (typically to a file, configurable to syslog) and requiring secure configuration files.[67][68]
