Policy Enforcement¶
Configure and enforce email policies to control message handling based on content, sender, recipient, size, and other criteria.
Overview¶
Mailborder's policy enforcement system allows you to:
- Control message flow based on sender/recipient
- Enforce size limits on messages and attachments
- Block file types by extension or content
- Restrict relay to authorized users/networks
- Apply custom rules based on headers, content, or metadata
- Override spam/virus decisions for specific scenarios
Policy Evaluation Order¶
1. Connection Policy (IP-based)
↓
2. Authentication Policy (SMTP AUTH required?)
↓
3. Relay Policy (authorized to send?)
↓
4. Sender Policy (from address allowed?)
↓
5. Recipient Policy (to address allowed?)
↓
6. Size Policy (message/attachment limits)
↓
7. Content Policy (attachment types, keywords)
↓
8. Spam/Virus Policy (override thresholds)
↓
9. Custom Policies (user-defined rules)
Connection Policies¶
IP-based Access Control¶
Allow specific networks:
sudo mb-policy add connection --allow --source 192.168.1.0/24 \
--description "Internal network"
sudo mb-policy add connection --allow --source 10.0.0.0/8 \
--description "Corporate VPN"
Block specific IPs:
Rate limiting by IP:
sudo mb-policy add connection --ratelimit --source 0.0.0.0/0 \
--limit 100 --period 3600 \
--description "Max 100 emails per hour per IP"
Connection Security¶
Require TLS:
Minimum TLS version:
Reject plaintext AUTH:
Authentication Policies¶
SMTP AUTH Requirements¶
Require authentication for all:
Require auth for specific domains:
Exempt internal network:
Authentication Methods¶
Allowed methods:
Disable weak methods:
Relay Policies¶
Relay Authorization¶
Authorized relay networks:
Require authentication for relay:
Authorized domains to relay for:
Open Relay Protection¶
Open Relay Risk
An open relay allows anyone to send email through your server, leading to blacklisting and abuse.
Verify relay is closed:
Expected output:
Testing relay configuration...
[PASS] Relay denied for external → external
[PASS] Relay allowed for authenticated users
[PASS] Relay allowed for local networks
Status: SECURE - Not an open relay
Relay Restrictions¶
Maximum recipients per message:
Maximum messages per connection:
Rate limit per authenticated user:
sudo mb-policy add relay --ratelimit --user * \
--limit 500 --period 3600 \
--description "500 emails/hour per user"
Sender Policies¶
Sender Restrictions¶
Block specific senders:
Allow only specific senders:
sudo mb-policy add sender --allow --from @trusted-domain.com
sudo mb-policy add sender --deny --from *
Require SPF pass:
Sender Verification¶
Verify sender domain exists:
Reject invalid sender format:
Reject null sender (except bounce messages):
Sender Spoofing Protection¶
Reject mismatched domains:
sudo mb-policy add sender --reject-mismatch \
--description "Reject From header != envelope sender domain"
DMARC enforcement:
sudo mb-config set policy.dmarc_enforce true
sudo mb-config set policy.dmarc_action quarantine # or reject
Recipient Policies¶
Recipient Validation¶
Verify recipient exists:
LDAP recipient validation:
Reject unknown recipients:
Recipient Limits¶
Maximum recipients per message:
Per-user recipient limits:
sudo mb-policy add recipient --limit --user user@example.com \
--max 1000 --period 86400 \
--description "Max 1000 recipients/day"
Recipient Lists¶
Allow only internal recipients:
sudo mb-policy add recipient --allow --domain example.com
sudo mb-policy add recipient --deny --domain *
Block specific recipient:
Size Policies¶
Message Size Limits¶
Global message size limit:
Per-sender size limits:
sudo mb-policy add size --limit --from @external-domain.com \
--max-size 10485760 \
--description "10 MB limit for external senders"
Reject oversized messages:
Custom rejection message:
sudo mb-config set policy.oversized_message \
"Message exceeds 50 MB limit. Please use file sharing service."
Attachment Size Limits¶
Maximum attachment size:
Total attachments size:
Maximum number of attachments:
Content Policies¶
File Type Restrictions¶
Block executable files:
sudo mb-antivirus-block-ext add .exe
sudo mb-antivirus-block-ext add .scr
sudo mb-antivirus-block-ext add .bat
sudo mb-antivirus-block-ext add .cmd
sudo mb-antivirus-block-ext add .com
sudo mb-antivirus-block-ext add .pif
Block scripts:
sudo mb-antivirus-block-ext add .vbs
sudo mb-antivirus-block-ext add .js
sudo mb-antivirus-block-ext add .jar
Allow exceptions for whitelisted senders:
Content Filtering¶
Block messages containing keywords:
sudo mb-policy add content --reject --body-contains "confidential" \
--action quarantine \
--description "Flag emails with 'confidential' for review"
Require encryption for sensitive data:
sudo mb-policy add content --require-encryption \
--body-regex "SSN|social security|tax ID" \
--action reject \
--message "Sensitive information must be encrypted"
Header Policies¶
Require specific headers:
Block messages with spoofed headers:
Add custom headers:
Spam and Virus Overrides¶
Per-Sender Thresholds¶
Lower threshold for external senders:
sudo mb-policy add spam --threshold \
--from @external-domain.com \
--pass 5.0 --quarantine 5.0 --reject 15.0
Higher threshold for trusted partners:
sudo mb-policy add spam --threshold \
--from @trusted-partner.com \
--pass 8.0 --quarantine 8.0 --reject 25.0
Skip spam check for whitelisted:
Virus Scan Overrides¶
Skip virus scan for specific senders:
Security Risk
Skipping virus scans should only be done for highly trusted sources.
Lower scan recursion for large archives:
Custom Policies¶
Rule-Based Policies¶
Create custom policy:
sudo mb-policy create --name "executive-protection" \
--description "Enhanced filtering for executives"
Add conditions:
sudo mb-policy rule add executive-protection \
--condition "recipient in @example.com" \
--condition "recipient contains 'ceo|cfo|president'" \
--action "set spam threshold 4.0" \
--action "require spf pass" \
--action "require dkim pass"
Enable policy:
Time-Based Policies¶
Business hours policy:
sudo mb-policy create --name "business-hours" \
--schedule "Mon-Fri 08:00-18:00 America/New_York"
sudo mb-policy rule add business-hours \
--action "allow all"
After-hours restrictions:
sudo mb-policy create --name "after-hours" \
--schedule "Mon-Fri 18:00-08:00,Sat-Sun 00:00-23:59"
sudo mb-policy rule add after-hours \
--condition "size > 10485760" \
--action "defer until 08:00"
Conditional Actions¶
Quarantine high-risk combinations:
sudo mb-policy rule add high-risk \
--condition "from @*.ru" \
--condition "has attachment .zip" \
--condition "spam score > 4.0" \
--action quarantine \
--notify admin@example.com
Enhanced logging:
sudo mb-policy rule add audit-sensitive \
--condition "recipient contains 'finance|accounting|payroll'" \
--action "log detailed" \
--action "add header X-Policy-Match: sensitive"
Policy Management¶
List Policies¶
View all policies:
Example output:
Policy Name Status Priority Matches
---------------------------------------------------------
connection-ratelimit enabled 100 5,234
require-auth-external enabled 200 1,892
executive-protection enabled 300 45
block-executables enabled 400 12
after-hours enabled 500 0 (schedule inactive)
View specific policy:
Modify Policies¶
Change priority:
Enable/disable:
Delete policy:
Testing Policies¶
Test against email:
Example output:
Testing policy evaluation...
Matched policies:
[PASS] connection-ratelimit (priority 100)
[PASS] require-auth-external (priority 200)
[MATCH] executive-protection (priority 300)
- Condition matched: recipient contains 'ceo'
- Action: set spam threshold 4.0
- Action: require spf pass
[SKIP] block-executables (no attachments)
Final verdict: PASS (with modified threshold)
Dry-run mode:
This logs policy actions without enforcing them.
Policy Examples¶
Example 1: Department-Specific Filtering¶
Finance department - strict filtering:
sudo mb-policy create --name "finance-strict"
sudo mb-policy rule add finance-strict \
--condition "recipient in finance@example.com" \
--action "set spam threshold 3.0" \
--action "require spf pass" \
--action "require dkim pass" \
--action "reject score > 10.0" \
--action "quarantine has-attachment .exe"
Example 2: Partner Organization Integration¶
Trusted partner with relaxed filtering:
sudo mb-policy create --name "partner-acme"
sudo mb-policy rule add partner-acme \
--condition "from @acme-corp.com" \
--condition "spf pass" \
--action "set spam threshold 8.0" \
--action "skip greylisting" \
--action "allow extension .exe"
Example 3: Bulk Sender Policy¶
Mailing list with size/attachment restrictions:
sudo mb-policy create --name "mailing-lists"
sudo mb-policy rule add mailing-lists \
--condition "from @newsletter-service.com" \
--action "max size 5242880" \
--action "reject has-attachment" \
--action "max recipients 1000"
Example 4: Geographic Restrictions¶
Block emails from high-risk countries:
sudo mb-policy create --name "geo-restrictions"
sudo mb-policy rule add geo-restrictions \
--condition "geoip from CN,RU,KP" \
--condition "not from @known-partner.com" \
--action "quarantine score > 2.0" \
--action "reject score > 5.0"
Example 5: Executive Protection¶
VIP protection with multiple layers:
sudo mb-policy create --name "vip-protection"
sudo mb-policy rule add vip-protection \
--condition "recipient in ceo@,cfo@,president@" \
--action "set spam threshold 2.0" \
--action "reject has-url-shortener" \
--action "quarantine new-sender" \
--action "require dmarc pass" \
--action "block extension .exe,.scr,.bat" \
--action "notify security@example.com"
Monitoring Policy Enforcement¶
Policy Statistics¶
View policy matches:
Example output:
Last 24 hours:
Policy Matches Actions
-----------------------------------------------
connection-ratelimit 5,234 100 deferred
executive-protection 45 45 threshold adjusted
block-executables 12 12 rejected
geo-restrictions 234 180 quarantined, 54 rejected
Per-policy details:
Real-time Monitoring¶
Watch policy log:
Filter by policy:
Audit Trail¶
Policy change history:
Example output:
2025-01-13 10:23:45 admin@example.com POLICY_CREATED executive-protection
2025-01-13 10:25:12 admin@example.com POLICY_ENABLED executive-protection
2025-01-13 14:30:00 admin@example.com POLICY_MODIFIED executive-protection (threshold changed)
Troubleshooting¶
Policy Not Matching¶
Debug policy evaluation:
Check policy syntax:
Common issues: 1. Priority too low (other policies take precedence) 2. Condition syntax error 3. Policy disabled 4. Conflicting policies
Unintended Rejections¶
Find which policy rejected message:
Temporarily disable policy:
Review and adjust conditions:
sudo mb-policy show problematic-policy
sudo mb-policy rule modify problematic-policy --condition "..."
Performance Issues¶
Too many policies:
Optimize policy order: - Most frequently matched policies at low priority numbers - Expensive checks (regex, content scanning) after simple checks
Enable policy caching:
Best Practices¶
Policy Design¶
- Start simple - Add complexity as needed
- Test before enforcing - Use dry-run mode
- Document policies - Include description and reason
- Order by frequency - Most common matches first
- Avoid over-blocking - Better to quarantine than reject
Security Recommendations¶
- Always enforce relay restrictions - Prevent open relay
- Require authentication - For external senders
- Block dangerous extensions - .exe, .scr, .vbs, etc.
- Implement rate limiting - Prevent abuse
- Use whitelists sparingly - Review regularly
Maintenance¶
- Review statistics weekly - Identify ineffective policies
- Update exceptions - As business needs change
- Monitor false positives - Adjust thresholds
- Audit policy changes - Track who modified what
- Test regularly - Ensure policies work as intended
Performance Optimization¶
- Limit policy count - Combine similar policies
- Optimize condition order - Fast checks first
- Cache policy results - For repeated evaluations
- Use specific conditions - Avoid wildcards when possible
- Monitor processing time - Remove slow policies
See Also¶
- Spam Detection - Spam filtering configuration
- Virus Scanning - Antivirus settings
- GeoIP Filtering - Geographic restrictions
- Whitelist/Blacklist - Sender filtering
- SPF/DKIM/DMARC - Email authentication