A lightweight SMTP relay server written in Go, designed for efficient email delivery with configurable rate limiting and TLS support.
- Supports multiple SMTP protocols:
- SMTPS/TLS (port 465)
- STARTTLS (port 587)
- Unencrypted SMTP (port 25)
- Configurable encryption per listener
- Configurable rate limiting
- IP blocking
- Multi-platform support (Windows, Linux, MacOS)
- Detailed logging
- Automatic service installation
- Comprehensive service management
- Log rotation and monitoring
- Go 1.20+ installed
- Git installed
- System administrator privileges
- Clone the repository:
git clone https://github.com/WikiHacker/go-relay-server.git
cd go-relay-server
- Install dependencies:
go mod download
-
Configure the server by editing
config/config.json
-
Compile the server:
# Linux/MacOS
chmod +x script/compile.sh
./script/compile.sh
# Windows
./script/compile.ps1
- Install and start the service:
# Linux/MacOS
sudo ./script/setup-installation.sh
# Windows (Run as Administrator)
.\script\setup-installation.ps1
Edit config/config.json
with your desired settings:
{
"Listeners": [
{
"host": "0.0.0.0",
"port": "25",
"encryption": "none",
"require_auth": false
},
{
"host": "0.0.0.0",
"port": "465",
"encryption": "tls",
"require_auth": true
},
{
"host": "0.0.0.0",
"port": "587",
"encryption": "starttls",
"require_auth": true
}
],
"DefaultRelay": "smtp.example.com:25",
"TLSCertFile": "certs/cert.pem",
"TLSKeyFile": "certs/key.pem",
"RateLimiting": {
"RequestsPerMinute": 100,
"BurstLimit": 20,
"ExemptIPs": ["127.0.0.1"]
},
"BlockList": ["spamdomain.com"]
}
The server provides comprehensive service management through the manage-service.sh
script:
sudo ./script/manage-service.sh install [install-dir]
- Start service:
sudo ./script/manage-service.sh start
- Stop service:
sudo ./script/manage-service.sh stop
- Restart service:
sudo ./script/manage-service.sh restart
- Check status:
sudo ./script/manage-service.sh status
- View logs:
sudo ./script/manage-service.sh logs
- Uninstall service:
sudo ./script/manage-service.sh uninstall
Run all commands from an elevated PowerShell prompt:
# Install service
.\script\manage-service.ps1 install
# Start service
.\script\manage-service.ps1 start
# View logs
.\script\manage-service.ps1 logs
The server requires the following directory structure:
.
├── build/ # Compiled binaries
├── config/ # Configuration files
│ ├── config.json # Main configuration
│ └── certs/ # TLS certificates (if using TLS)
├── logs/ # Log files (created automatically)
│ ├── output.log # Standard output
│ └── error.log # Error output
└── script/ # Management scripts
Logs are automatically rotated when they reach 100MB. To configure:
- Edit
config/config.json
:
{
"Logging": {
"MaxSizeMB": 100,
"MaxBackups": 5,
"MaxAgeDays": 30
}
}
Configure rate limiting in config/config.json
:
{
"RateLimiting": {
"RequestsPerMinute": 100,
"BurstLimit": 20,
"ExemptIPs": ["127.0.0.1"]
}
}
To enable TLS, provide certificate files in config/certs/
and update:
{
"Listeners": [
{
"host": "0.0.0.0",
"port": "465",
"encryption": "tls",
"require_auth": true
}
],
"TLSCertFile": "certs/cert.pem",
"TLSKeyFile": "certs/key.pem"
}
-
Service fails to start
- Verify configuration file exists and is valid
- Check logs:
sudo ./script/manage-service.sh logs
- Ensure required ports are open
-
Permission denied errors
- Run commands with sudo/Administrator privileges
- Verify installation directory permissions
-
Connection issues
- Verify firewall settings
- Check network connectivity
- Validate TLS certificates (if using)
MIT License