5.1 KiB
5.1 KiB
Email Rules Sync System
This script synchronizes email rules from AWS DynamoDB to the mail server, enabling:
- Out-of-Office Auto-Replies (Sieve scripts)
- Email Forwarding (Postfix virtual aliases)
How It Works
┌─────────────┐
│ DynamoDB │ ← Rules stored here (via Web UI)
│ email-rules │
└──────┬──────┘
│
│ Sync Script (every 5 minutes)
↓
┌─────────────────────────────────────┐
│ Mail Server (Docker) │
│ ┌────────────┐ ┌───────────────┐ │
│ │ Sieve │ │ Postfix │ │
│ │ Scripts │ │Virtual Aliases│ │
│ │ (OOO) │ │ (Forwarding) │ │
│ └────────────┘ └───────────────┘ │
└─────────────────────────────────────┘
Setup
1. Install Dependencies
cd /home/timo/config-email/sync
npm install
2. Configure Environment
The .env file is already configured with:
- AWS credentials
- DynamoDB table name
- Mail server paths
3. Test Manual Sync
npm start
You should see output like:
🚀 Starting email rules sync...
📊 DynamoDB Table: email-rules
🌍 Region: us-east-2
📥 Fetching rules from DynamoDB...
✅ Found 2 email rules
📝 Processing Sieve scripts (Out-of-Office)...
✅ Created Sieve script for support@qrmaster.net
✅ Processed 1 Sieve scripts
📮 Updating virtual aliases (Forwarding)...
✅ Found 0 forwarding rules
✅ Updated virtual aliases
🔄 Applying changes to mail server...
✅ Postfix reloaded
✅ Dovecot reloaded
✨ Sync completed successfully!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total Rules: 2
OOO Active: 1
Forwarding Active: 0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
4. Install as Cron Job (Automatic Sync)
./install-cron.sh
This will:
- Run sync every 5 minutes
- Log to
/tmp/email-rules-sync.log
Usage
View Sync Logs
tail -f /tmp/email-rules-sync.log
Manual Sync
cd /home/timo/config-email/sync
npm start
Check Current Cron Jobs
crontab -l
Remove Cron Job
crontab -l | grep -v "email-rules-sync" | crontab -
What Gets Generated
1. Sieve Scripts (Out-of-Office)
Location: /home/timo/docker-mailserver/docker-data/dms/mail-data/{domain}/{user}/home/.dovecot.sieve
Example for support@qrmaster.net:
require ["vacation", "variables"];
# Auto-Reply / Out-of-Office
# Generated by Email Rules Sync System
# Last updated: 2025-12-27T12:00:00.000Z
if true {
vacation
:days 1
:subject "Out of Office"
"I am currently out of office and will respond when I return.";
}
2. Virtual Aliases (Forwarding)
Location: /home/timo/docker-mailserver/docker-data/dms/config/postfix-virtual.cf
Example:
# Virtual Aliases - Email Forwarding
# Generated by Email Rules Sync System
# Last updated: 2025-12-27T12:00:00.000Z
# Forwarding for support@qrmaster.net
support@qrmaster.net forward1@example.com,forward2@example.com
DynamoDB Schema
The sync script expects this schema:
{
email_address: "support@qrmaster.net", // Primary Key
ooo_active: true, // Enable/disable auto-reply
ooo_message: "I am out of office...", // Auto-reply message
ooo_content_type: "text", // "text" or "html"
forwards: ["user@example.com"], // Array of forward addresses
last_updated: "2025-12-27T12:00:00.000Z" // Timestamp
}
Troubleshooting
Script fails to connect to DynamoDB
Check AWS credentials in .env:
cat .env | grep AWS
Sieve scripts not working
-
Check script was created:
ls -la /home/timo/docker-mailserver/docker-data/dms/mail-data/qrmaster.net/support/home/ -
Check Dovecot logs:
docker logs mailserver-new 2>&1 | grep -i sieve
Forwarding not working
-
Check virtual aliases file:
cat /home/timo/docker-mailserver/docker-data/dms/config/postfix-virtual.cf -
Check Postfix logs:
docker logs mailserver-new 2>&1 | grep -i virtual -
Reload Postfix manually:
docker exec mailserver-new postfix reload
Architecture
Web UI (React)
↓
Backend API (Express)
↓
DynamoDB (email-rules)
↓
Sync Script (Node.js) ← You are here
↓
Mail Server (Dovecot + Postfix)
Files
sync.js- Main sync scriptpackage.json- Dependencies.env- Configurationinstall-cron.sh- Cron job installerREADME.md- This file
Support
For issues, check:
- Sync logs:
/tmp/email-rules-sync.log - Mail server logs:
docker logs mailserver-new - DynamoDB table: AWS Console → DynamoDB → email-rules