بیشتر سرورها لازم نیست ایمیل دریافت کنند؛ فقط باید بتوانند هشدار بفرستند. ارسال مستقیم از IP سرور معمولاً به اسپم میرود. راه درست: ارسال از طریق سرور SMTP سازمان با احراز هویت.
۱. نصب
sudo apt update
sudo DEBIAN_FRONTEND=noninteractive apt install -y postfix libsasl2-modules mailutils۲. پیکربندی relay
sudo postconf -e 'relayhost = [mail.example.ir]:587'
sudo postconf -e 'smtp_sasl_auth_enable = yes'
sudo postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
sudo postconf -e 'smtp_sasl_security_options = noanonymous'
sudo postconf -e 'smtp_tls_security_level = encrypt'
sudo postconf -e 'inet_interfaces = loopback-only'
sudo postconf -e 'mydestination = 'inet_interfaces = loopback-only تضمین میکند Postfix از شبکه هیچ ایمیلی نپذیرد.
۳. رمز حساب ارسال
echo '[mail.example.ir]:587 alerts@example.ir:رمز-حساب' | sudo tee /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd۴. فرستندهی یکسان
سرور SMTP معمولاً فقط اجازه میدهد با همان آدرس حساب ارسال کنید. همهی فرستندههای محلی را به آن نگاشت کنید:
echo '/.+/ alerts@example.ir' | sudo tee /etc/postfix/sender_canonical
sudo postconf -e 'sender_canonical_maps = regexp:/etc/postfix/sender_canonical'ایمیلهای root را هم به صندوق مدیر بفرستید:
echo 'root: admin@example.ir' | sudo tee -a /etc/aliases
sudo newaliases
sudo systemctl restart postfix۵. آزمایش
echo "test from $(hostname)" | mail -s "Postfix relay test" admin@example.ir
sudo tail -n 20 /var/log/mail.log
mailqدر لاگ باید status=sent ببینید.