Skip to content

A minimal SMTP server that captures and saves email attachments to a specified directory.

Notifications You must be signed in to change notification settings

flyryan/SMTPdump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SMTP Attachment Dumper

A simple SMTP server that saves email attachments to a specified directory.

Configuration

Edit the CONFIG section at the top of smtp_dumper.py:

CONFIG = {
    'host': '0.0.0.0',       # Listen on all interfaces
    'port': 2525,            # Port to listen on
    'attachment_dir': '/var/smtp-dumper/attachments',  # Directory to save attachments
    'log_dir': '/var/smtp-dumper/logs'                # Directory to save logs
}

Installation

  1. Install Python dependencies:
sudo python3 -m pip install aiosmtpd>=1.4.2
  1. Setup service (on RedHat):
# Create service user
sudo useradd -r -s /sbin/nologin smtp-dumper

# Create directories
sudo mkdir -p /opt/smtp-dumper
sudo mkdir -p /var/smtp-dumper/attachments
sudo mkdir -p /var/smtp-dumper/logs

# Copy files
sudo cp smtp_dumper.py /opt/smtp-dumper/
sudo cp smtp-dumper.service /etc/systemd/system/

# Set permissions
sudo chown -R smtp-dumper:smtp-dumper /opt/smtp-dumper
sudo chown -R smtp-dumper:smtp-dumper /var/smtp-dumper

# Verify Python module is available to the service user
sudo -u smtp-dumper python3 -c "from aiosmtpd.controller import Controller"

# Enable and start service
sudo systemctl daemon-reload
sudo systemctl enable smtp-dumper
sudo systemctl start smtp-dumper

Local Testing

  1. Create local directories:
mkdir -p attachments logs
  1. Start the server:
python3 smtp_dumper.py
  1. In another terminal, run the test script:
python3 test_send.py

The test script will send an email with test.txt as an attachment. You should see a success message and the attachment will be saved in the attachments directory with a timestamp prefix.

Monitoring

  • Check service status: sudo systemctl status smtp-dumper
  • View logs: sudo tail -f /var/smtp-dumper/logs/smtp_dumper.log
  • Check saved files: ls -l /var/smtp-dumper/attachments/

Troubleshooting

  1. If service fails to start:

    • Check logs: journalctl -u smtp-dumper
    • Verify permissions on directories
    • Ensure port 2525 is available and not blocked by firewall
    • Verify Python dependencies are installed
  2. If attachments aren't saving:

    • Check directory permissions
    • Verify enough disk space
    • Review logs for specific errors
    • Ensure email contains proper attachments
  3. Common Issues:

    • Port already in use: Check if another service is using port 2525
    • Permission denied: Check directory and file ownership

About

A minimal SMTP server that captures and saves email attachments to a specified directory.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages