rcptFilter plugin enforces domain-based recipient restrictions by only accepting RCPT TO commands for recipients whose domain is in an allowed list. This is useful for creating closed mail systems or relay servers that only serve specific domains.
What It Does
The rcptFilter plugin:- Maintains a list of allowed recipient domains
- Checks each RCPT TO command against the allowed domains
- Rejects recipients from domains not in the allowed list
- Performs case-insensitive domain matching
- Returns a 550 error code for rejected recipients
Function Signature
Parameters
Array of domain names that are allowed to receive mail. Only recipients with email addresses from these domains will be accepted. Domain matching is case-insensitive.
Usage
Import and configure the rcptFilter plugin with your allowed domains:Single Domain Example
Corporate Email System Example
Error Response
When a recipient from an unauthorized domain is specified:Implementation
The plugin converts domain names to lowercase and stores them in a Set for efficient lookup:How Domain Extraction Works
The plugin extracts the domain from the email address using:[email protected]→example.com[email protected]→mycompany.com(case-insensitive)invalid-email→""(empty string, will be rejected)
Case-Insensitive MatchingThe plugin performs case-insensitive domain matching. Both the allowed domains and incoming recipient domains are converted to lowercase before comparison.You can specify allowed domains in any case:These will match:
Multiple Recipients
The plugin checks each recipient individually during the SMTP transaction:Use Cases
- Corporate Mail Servers: Only accept mail for company domains
- Multi-Tenant Systems: Restrict each tenant to their own domains
- Relay Servers: Only relay mail for authorized domains
- Testing Environments: Prevent accidentally sending to external addresses
- Closed Mail Systems: Create isolated email networks
Combining with Other Filters
You can combine rcptFilter with other plugins for comprehensive filtering:Performance
The plugin uses aSet for O(1) domain lookup, making it efficient even with many allowed domains. The overhead per RCPT TO command is minimal:
- Extract domain (one string split operation)
- Convert to lowercase
- Set lookup (O(1))