Sendmail is a free and open-source Mail Server. A general purpose internetwork email routing facility
1. Prerequisites
2. Supported Operating Systems
This guide supports installation on:
3. Installation
RHEL/CentOS/Rocky Linux/AlmaLinux
bash
# Install EPEL repository if needed
sudo dnf install -y epel-release
# Install sendmail
sudo dnf install -y sendmail sendmail-cf, m4
# Enable and start service
sudo systemctl enable --now sendmail
# Configure firewall
sudo firewall-cmd --permanent --add-service=sendmail
sudo firewall-cmd --reload
# Verify installation
sendmail --version || systemctl status sendmail
Debian/Ubuntu
bash
# Update package index
sudo apt update
# Install sendmail
sudo apt install -y sendmail sendmail-cf, m4
# Enable and start service
sudo systemctl enable --now sendmail
# Configure firewall
sudo ufw allow 25/587
# Verify installation
sendmail --version || systemctl status sendmail
Arch Linux
bash
# Install sendmail
sudo pacman -S sendmail
# Enable and start service
sudo systemctl enable --now sendmail
# Verify installation
sendmail --version || systemctl status sendmail
Alpine Linux
bash
# Install sendmail
apk add --no-cache sendmail
# Enable and start service
rc-update add sendmail default
rc-service sendmail start
# Verify installation
sendmail --version || rc-service sendmail status
openSUSE/SLES
bash
# Install sendmail
sudo zypper install -y sendmail sendmail-cf, m4
# Enable and start service
sudo systemctl enable --now sendmail
# Configure firewall
sudo firewall-cmd --permanent --add-service=sendmail
sudo firewall-cmd --reload
# Verify installation
sendmail --version || systemctl status sendmail
macOS
bash
# Using Homebrew
brew install sendmail
# Start service
brew services start sendmail
# Verify installation
sendmail --version
FreeBSD
bash
# Using pkg
pkg install sendmail
# Enable in rc.conf
echo 'sendmail_enable="YES"' >> /etc/rc.conf
# Start service
service sendmail start
# Verify installation
sendmail --version || service sendmail status
Windows
powershell
# Using Chocolatey
choco install sendmail
# Or using Scoop
scoop install sendmail
# Verify installation
sendmail --version
Initial Configuration
Basic Configuration
bash
# Create configuration directory if needed
sudo mkdir -p /etc/mail
# Set up basic configuration
sudo tee /etc/mail/sendmail.conf << 'EOF'
# Sendmail Configuration
MaxDaemonChildren=100
EOF
# Test configuration
sudo sendmail -t || sudo sendmail configtest
# Reload service
sudo systemctl reload sendmail
Security Hardening
bash
# Set appropriate permissions
sudo chown -R sendmail:sendmail /etc/mail
sudo chmod 750 /etc/mail
# Enable security features
# See security section for detailed hardening steps
5. Service Management
systemd (RHEL, Debian, Ubuntu, Arch, openSUSE)
bash
# Enable service
sudo systemctl enable sendmail
# Start service
sudo systemctl start sendmail
# Stop service
sudo systemctl stop sendmail
# Restart service
sudo systemctl restart sendmail
# Reload configuration
sudo systemctl reload sendmail
# Check status
sudo systemctl status sendmail
# View logs
sudo journalctl -u sendmail -f
OpenRC (Alpine Linux)
bash
# Enable service
rc-update add sendmail default
# Start service
rc-service sendmail start
# Stop service
rc-service sendmail stop
# Restart service
rc-service sendmail restart
# Check status
rc-service sendmail status
rc.d (FreeBSD)
bash
# Enable in /etc/rc.conf
echo 'sendmail_enable="YES"' >> /etc/rc.conf
# Start service
service sendmail start
# Stop service
service sendmail stop
# Restart service
service sendmail restart
# Check status
service sendmail status
launchd (macOS)
bash
# Using Homebrew services
brew services start sendmail
brew services stop sendmail
brew services restart sendmail
# Check status
brew services list | grep sendmail
Windows Service Manager
powershell
# Start service
net start sendmail
# Stop service
net stop sendmail
# Using PowerShell
Start-Service sendmail
Stop-Service sendmail
Restart-Service sendmail
# Check status
Get-Service sendmail
Advanced Configuration
Performance Optimization
bash
# Configure performance settings
cat >> /etc/mail/sendmail.conf << 'EOF'
MaxDaemonChildren=100
EOF
# Apply system tuning
sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65535
# Restart service
sudo systemctl restart sendmail
Clustering and High Availability
bash
# Configure clustering (if supported)
# See official documentation for cluster setup
# Basic load balancing setup example
# Configure multiple instances on different ports
Reverse Proxy Setup
nginx Configuration
nginx
upstream sendmail_backend {
server 127.0.0.1:25/587;
server 127.0.0.1:{default_port}1 backup;
}
server {
listen 80;
server_name sendmail.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name sendmail.example.com;
ssl_certificate /etc/ssl/certs/sendmail.example.com.crt;
ssl_certificate_key /etc/ssl/private/sendmail.example.com.key;
location / {
proxy_pass http://sendmail_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket support (if needed)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Apache Configuration
apache
<VirtualHost *:80>
ServerName sendmail.example.com
Redirect permanent / https://sendmail.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName sendmail.example.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/sendmail.example.com.crt
SSLCertificateKeyFile /etc/ssl/private/sendmail.example.com.key
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:25/587/
ProxyPassReverse / http://127.0.0.1:25/587/
# WebSocket support (if needed)
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://127.0.0.1:25/587/$1" [P,L]
</VirtualHost>
HAProxy Configuration
haproxy
frontend sendmail_frontend
bind *:80
bind *:443 ssl crt /etc/ssl/certs/sendmail.pem
redirect scheme https if !{ ssl_fc }
default_backend sendmail_backend
backend sendmail_backend
balance roundrobin
option httpchk GET /health
server sendmail1 127.0.0.1:25/587 check
server sendmail2 127.0.0.1:{default_port}1 check backup
Security Configuration
Basic Security Setup
bash
# Set appropriate permissions
sudo chown -R sendmail:sendmail /etc/mail
sudo chmod 750 /etc/mail
# Configure firewall
sudo firewall-cmd --permanent --add-service=sendmail
sudo firewall-cmd --reload
# Enable SELinux policies (if applicable)
sudo setsebool -P httpd_can_network_connect on
# Configure fail2ban
sudo tee /etc/fail2ban/jail.d/sendmail.conf << 'EOF'
[sendmail]
enabled = true
port = 25/587
filter = sendmail
logpath = /var/log/mail/*.log
maxretry = 5
bantime = 3600
EOF
SSL/TLS Configuration
bash
# Generate SSL certificates
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/sendmail.key \
-out /etc/ssl/certs/sendmail.crt
# Configure SSL in sendmail
# See official documentation for SSL configuration
Database Setup
PostgreSQL Backend (if applicable)
bash
# Create database and user
sudo -u postgres psql << EOF
CREATE DATABASE sendmail_db;
CREATE USER sendmail_user WITH ENCRYPTED PASSWORD 'secure_password';
GRANT ALL PRIVILEGES ON DATABASE sendmail_db TO sendmail_user;
EOF
# Configure sendmail to use PostgreSQL
# See official documentation for database configuration
MySQL/MariaDB Backend (if applicable)
bash
# Create database and user
sudo mysql << EOF
CREATE DATABASE sendmail_db;
CREATE USER 'sendmail_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON sendmail_db.* TO 'sendmail_user'@'localhost';
FLUSH PRIVILEGES;
EOF
Performance Optimization
System Tuning
bash
# Kernel parameters
sudo tee -a /etc/sysctl.conf << EOF
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.ip_local_port_range = 1024 65535
net.core.netdev_max_backlog = 5000
vm.swappiness = 10
EOF
sudo sysctl -p
# Sendmail specific tuning
MaxDaemonChildren=100
Resource Limits
bash
# Configure system limits
sudo tee -a /etc/security/limits.conf << EOF
sendmail soft nofile 65535
sendmail hard nofile 65535
sendmail soft nproc 32768
sendmail hard nproc 32768
EOF
Monitoring
Prometheus Integration
yaml
# prometheus.yml configuration
scrape_configs:
- job_name: 'sendmail'
static_configs:
- targets: ['localhost:25/587']
metrics_path: '/metrics'
Health Checks
bash
# Basic health check script
#!/bin/bash
if systemctl is-active --quiet sendmail; then
echo "Sendmail is running"
exit 0
else
echo "Sendmail is not running"
exit 1
fi
Log Monitoring
bash
# Configure log rotation
sudo tee /etc/logrotate.d/sendmail << 'EOF'
/var/log/mail/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
create 0640 sendmail sendmail
postrotate
systemctl reload sendmail > /dev/null 2>&1 || true
endscript
}
EOF
9. Backup and Restore
Backup Script
bash
#!/bin/bash
# Sendmail backup script
BACKUP_DIR="/backup/sendmail"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p "$BACKUP_DIR"
# Stop service (if required)
systemctl stop sendmail
# Backup configuration
tar -czf "$BACKUP_DIR/sendmail-config-$DATE.tar.gz" /etc/mail
# Backup data (adjust paths as needed)
tar -czf "$BACKUP_DIR/sendmail-data-$DATE.tar.gz" /var/lib/sendmail
# Start service
systemctl start sendmail
# Clean old backups (keep 30 days)
find "$BACKUP_DIR" -name "*.tar.gz" -mtime +30 -delete
echo "Backup completed: $BACKUP_DIR"
Restore Procedure
bash
# Stop service
sudo systemctl stop sendmail
# Restore configuration
sudo tar -xzf /backup/sendmail/sendmail-config-*.tar.gz -C /
# Restore data
sudo tar -xzf /backup/sendmail/sendmail-data-*.tar.gz -C /
# Set permissions
sudo chown -R sendmail:sendmail /etc/mail
sudo chown -R sendmail:sendmail /var/lib/sendmail
# Start service
sudo systemctl start sendmail
6. Troubleshooting
Common Issues
1. Service won't start:
bash
# Check logs
sudo journalctl -u sendmail -n 100
sudo tail -f /var/log/mail/*.log
# Check configuration
sudo sendmail -t || sudo sendmail configtest
# Check permissions
ls -la /etc/mail
ls -la /var/lib/sendmail
2. Connection refused:
bash
# Check if service is listening
sudo ss -tlnp | grep 25/587
sudo netstat -tlnp | grep 25/587
# Check firewall
sudo firewall-cmd --list-all
sudo iptables -L -n
# Test connection
telnet localhost 25/587
nc -zv localhost 25/587
3. Performance issues:
bash
# Check resource usage
top -p $(pgrep sendmail)
htop -p $(pgrep sendmail)
# Check connections
ss -ant | grep :25/587 | wc -l
# Monitor I/O
iotop -p $(pgrep sendmail)
Debug Mode
bash
# Run in debug mode
sudo sendmail -d
# or
sudo sendmail debug
# Increase log verbosity
# Edit configuration to enable debug logging
Integration Examples
Docker Compose
yaml
version: '3.8'
services:
sendmail:
image: sendmail:latest
container_name: sendmail
ports:
- "25/587:25/587"
volumes:
- ./config:/etc/mail
- ./data:/var/lib/sendmail
environment:
- sendmail_CONFIG=/etc/mail/sendmail.conf
restart: unless-stopped
networks:
- sendmail_net
networks:
sendmail_net:
driver: bridge
Kubernetes Deployment
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sendmail
spec:
replicas: 3
selector:
matchLabels:
app: sendmail
template:
metadata:
labels:
app: sendmail
spec:
containers:
- name: sendmail
image: sendmail:latest
ports:
- containerPort: 25/587
volumeMounts:
- name: config
mountPath: /etc/mail
volumes:
- name: config
configMap:
name: sendmail-config
---
apiVersion: v1
kind: Service
metadata:
name: sendmail
spec:
selector:
app: sendmail
ports:
- port: 25/587
targetPort: 25/587
type: LoadBalancer
Ansible Playbook
yaml
---
- name: Install and configure Sendmail
hosts: all
become: yes
tasks:
- name: Install sendmail
package:
name: sendmail
state: present
- name: Configure sendmail
template:
src: sendmail.conf.j2
dest: /etc/mail/sendmail.conf
owner: sendmail
group: sendmail
mode: '0640'
notify: restart sendmail
- name: Start and enable sendmail
systemd:
name: sendmail
state: started
enabled: yes
handlers:
- name: restart sendmail
systemd:
name: sendmail
state: restarted
Maintenance
Update Procedures
bash
# RHEL/CentOS/Rocky/AlmaLinux
sudo dnf update sendmail
# Debian/Ubuntu
sudo apt update && sudo apt upgrade sendmail
# Arch Linux
sudo pacman -Syu sendmail
# Alpine Linux
apk update && apk upgrade sendmail
# openSUSE
sudo zypper update sendmail
# FreeBSD
pkg update && pkg upgrade sendmail
# Always backup before updates
tar -czf /backup/sendmail-pre-update-$(date +%Y%m%d).tar.gz /etc/mail
# Restart after updates
sudo systemctl restart sendmail
Regular Maintenance Tasks
bash
# Clean logs
find /var/log/mail -name "*.log" -mtime +30 -delete
# Verify integrity
sudo sendmail --verify || sudo sendmail check
# Update databases (if applicable)
sudo sendmail-update-db
# Optimize performance
sudo sendmail-optimize
# Check for security updates
sudo sendmail --security-check
Additional Resources
---
Note: This guide is part of the HowToMgr collection. Always refer to official documentation for the most up-to-date information.