Το mailx (ή mail) είναι το κλασικό command-line email client για Unix/Linux. Χρησιμοποιείται σε scripts, cron jobs, monitoring alerts και automation για αποστολή emails χωρίς GUI.
# RHEL/CentOS 7
sudo yum install -y epel-release
sudo yum install -y mailx
# RHEL/CentOS 8 / Rocky / AlmaLinux
sudo dnf install -y epel-release
sudo dnf install -y mailx
# Verify
which mail
# /usr/bin/mail
mail --version
# mailx 12.5 7/5/10
# Απλό email
echo "Body του email" | mail -s "Subject" user@example.com
# Από αρχείο
mail -s "Log report" admin@example.com < /var/log/syslog
# Με συνημμένο (χρειάζεται uuencode ή mutt)
# mailx δεν υποστηρίζει attachments native - χρησιμοποιήστε mutt ή swaks
Το mailx χρειάζεται MTA (Mail Transfer Agent) για να στέλνει emails. Επιλογές:
sudo yum install -y postfix
sudo systemctl enable --now postfix
# Βασική ρύθμιση /etc/postfix/main.cf:
# myhostname = server.yourdomain.com
# myorigin = $myhostname
# inet_interfaces = loopback-only
# relayhost = [smtp.yourprovider.com]:587 # Αν χρησιμοποιείτε smart host
# smtp_sasl_auth_enable = yes
# smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# smtp_tls_security_level = encrypt
sudo yum install -y msmtp msmtp-mta
# ~/.msmtprc ή /etc/msmtprc
cat > ~/.msmtprc <<'EOF'
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-bundle.crt
logfile /var/log/msmtp.log
account gmail
host smtp.gmail.com
port 587
from your-email@gmail.com
user your-email@gmail.com
password your-app-password
account default : gmail
EOF
chmod 600 ~/.msmtprc
# Symlink για mailx
ln -sf /usr/bin/msmtp /usr/sbin/sendmail
sudo yum install -y ssmtp
# /etc/ssmtp/ssmtp.conf
root=admin@example.com
mailhub=smtp.gmail.com:587
AuthUser=your-email@gmail.com
AuthPass=your-app-password
UseTLS=YES
UseSTARTTLS=YES
hostname=server.yourdomain.com
# Test
echo "Test email from $(hostname) at $(date)" | mail -s "Test $(date)" admin@example.com
# Check logs
tail -f /var/log/maillog
# ή
journalctl -u postfix -f
# mailx υποστηρίζει HTML με σωστά headers
cat <<'EOF' | mail -s "$(echo -e "HTML Report\nContent-Type: text/html")" admin@example.com
System Report
Server: $(hostname)
Date: $(date)
Service Status
nginx Running
postgresql Running
EOF
# /etc/cron.daily/backup-report
#!/bin/bash
BACKUP_LOG="/var/log/backup.log"
if [ -f "$BACKUP_LOG" ]; then
mail -s "Daily Backup Report - $(hostname)" admin@example.com < "$BACKUP_LOG"
fi
# Monitoring alert
if ! systemctl is-active --quiet nginx; then
echo "NGINX is DOWN on $(hostname)!" | mail -s "ALERT: NGINX Down" admin@example.com
fi
| Tool | Pros | Cons |
|---|---|---|
| swaks | SMTP testing, attachments, TLS, authentication | Extra install |
| mutt | Full MIME, attachments, IMAP/POP3 | Complex config |
| sendmail/postfix | Native MTA, queue management | Complex setup |
| Python smtplib | Programmatic, flexible | Requires script |
inet_interfacesΠνευματικά δικαιώματα © Γνώση Υπολογιστών Όλα τα δικαιώματα διατηρούνται.