denylist plugin provides IP-based access control by blocking connections from a specified list of IP addresses. This is useful for preventing abuse, blocking known spam sources, or enforcing network policies.
What It Does
The denylist plugin:- Maintains a set of blocked IP addresses
- Checks incoming connections against the denylist
- Immediately rejects connections from blocked IPs
- Returns a 550 error code for blocked connections
Function Signature
Parameters
Array of IP addresses to block. Connections from these IPs will be immediately rejected with a 550 error code.
Usage
Import and configure the denylist plugin with your list of blocked IPs:Dynamic Denylist Example
You can build the denylist dynamically from external sources:Multiple IP Blocks
Error Response
When a blocked IP attempts to connect:onConnect phase, before any SMTP commands are processed.
Implementation
The plugin converts the IP array to a Set for efficient lookup and checks each connection:Performance Considerations
The denylist uses aSet for O(1) lookup performance, making it efficient even with large IP lists. However, for very large denylists (thousands of IPs), consider:
- Using a database-backed solution
- Implementing IP range blocking (CIDR notation)
- Caching the denylist in memory with periodic updates
- Using firewall rules at the network level
IP Address FormatThe plugin expects exact IP address matches. IPv4 addresses should be in dotted decimal notation (e.g., “192.168.1.1”). IPv6 addresses should be in standard notation (e.g., “2001:db8::1”).The plugin does not currently support:
- CIDR notation (e.g., “192.168.1.0/24”)
- Wildcard matching (e.g., “192.168.1.*”)
- Hostname blocking
Use Cases
- Abuse Prevention: Block IPs that have sent spam or malicious content
- Rate Limiting Enforcement: Temporarily block IPs that exceed rate limits
- Geographic Restrictions: Block IPs from specific countries or regions
- Security Incidents: Quickly block IPs involved in attacks
- Testing: Prevent test servers from sending to production