هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
postconf -e 'inet_interfaces = loopback-only'
postconf -e 'mydestination ='
postconf -e 'relayhost = [smtp.example.com]:587'
postconf -e 'smtp_sasl_auth_enable = yes'
postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
postconf -e 'smtp_sasl_security_options = noanonymous'
postconf -e 'smtp_tls_security_level = encrypt'
install -m 600 /dev/null /etc/postfix/sasl_passwd
echo '[smtp.example.com]:587 alerts@example.com:APP-PASSWORD' > /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
systemctl restart postfixStep by step
- Install Postfix ("Internet site" or "satellite" on Debian) and the SASL module:
libsasl2-modules(Debian/Ubuntu) orcyrus-sasl-plain(RHEL). - Send-only (quick answer, lines 1–2) — listen on localhost only, and treat no domain as local, so every mail goes to the relay.
- Relay with login (lines 3–6) — the brackets in
[smtp.example.com]mean "no MX lookup". Use an app password or SMTP user from your provider. - Force TLS (line 7) —
encryptrefuses to send the password without TLS. - Password file (lines 8–10) — readable by root only;
postmapbuildssasl_passwd.db. Runpostmapagain after every change. - Sender address — many relays only accept mail from your verified address. Map local senders (
root@web01) to it:
root@web01.example.com alerts@example.com
@web01.example.com alerts@example.compostconf -e 'smtp_generic_maps = hash:/etc/postfix/generic'
postmap /etc/postfix/generic && systemctl reload postfix- Send a test:
echo "Test from $(hostname) at $(date)" | mail -s "Postfix relay test" ops@example.com
journalctl -u postfix -n 20Look for status=sent (250 …).
- When mail does not arrive — read the queue and the reason:
mailq
postqueue -fAfter fixing, postqueue -f tries again; postsuper -d ALL deferred deletes stuck mail.
Check that it worked
The journal shows relay=smtp.example.com[…]:587, … status=sent (250 …); the test mail is in the inbox (not in spam); mailq says Mail queue is empty; ss -ltn | grep :25 shows Postfix listening on 127.0.0.1 only.
Common problems
| Problem | Cause | Fix |
|---|---|---|
SASL authentication failed | Wrong user/password, or no app password with MFA. | Check sasl_passwd; postmap again; use an app password. |
no mechanism available | SASL module missing. | Install libsasl2-modules / cyrus-sasl-plain. |
Sender address rejected | Relay accepts only your verified sender. | smtp_generic_maps to that address. |
Connection timed out to port 587 | Firewall or provider blocks outgoing 587. | Allow outgoing 587; check with nc -vz smtp.example.com 587. |
| Mail lands in spam | SPF/DKIM of your domain do not cover the relay. | Set SPF and DKIM for the relay provider. |
mail: command not found | No mail client installed. | Install mailutils / s-nail, or use sendmail -t. |
Go further
- Command pages: postconf, journalctl, ss.
- Next how-tos: Schedule a job with cron, Check the health of a disk, Send alerts to Slack or email, Check the DNS records of a domain.
- Learn it: Network services — Postfix. Full guide: Postfix.
1Why use a relay instead of sending mail directly from the server?
Direct mail from servers is often blocked (port 25) or marked as spam; a relay with login, TLS, SPF and DKIM is trusted.
2What does smtp_tls_security_level = encrypt do?
Postfix only sends mail to the relay over TLS, so the login and the mail are never sent in plain text.