Postfix for relaying SMTP, some info about my own configuration
Posted by jpluimers on 2020/03/20
I’ve a bunch of secondary MX servers using postfix (which I like a lot over sendmail). Basically all their configurations are very similar:
- To the file
/etc/postfix/relay
, add a list of domains to relay for, each ending with a space followed byOK
as per
[WayBack] Configure Postfix to relay mail to multiple internal mail servers w/different domains - Run
postmap /etc/postfix/relay
to update the relay database file. - Ensure that
/etc/postfix/main.cf
has these settings (note that the FQDN – in the examplesmtp3.example.org
– isn’t always returned byhostname --fqdn
, see below):inet_interfaces = all
myhostname = smtp3.example.org
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks, reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname, reject_unknown_helo_hostname
rcpostfix restart && rcpostfix status
Check the functionality with journalctl -u postfix.
FQDN – how to get myhostname
This usually gives a good indication of your external FQDN, but depending on your network circumstances it might not at all be the FQDN of your machine:
dig +noall +answer +short -x `curl -s ipv4.whatismyip.akamai.com` | sed 's/\.$//'
I got there through these StackExchange answers:
- [WayBack] linux – How do I get cURL to not show the progress bar? – Stack Overflow
- Reverse DNS lookup through
dig
: [WayBack] 10 Linux DIG Command Examples for DNS Lookup and [WayBack] linux – Bash: Reverse DNS Lookup of Active IP Addresses – Super User - remove the final
.
from thedig
answer: [WayBack] text processing – Remove last character from line – Unix & Linux Stack Exchange
Testing with sendEmail
Then test with sendEmail from [WayBack] GitHub – mogaal/sendemail: lightweight, command line SMTP email client, with statements like these
The most recent version is now at [Wayback/Archive.is] GitHub – zehm/sendEmail: SendEmail is a lightweight, command line SMTP email client.
sendEmail -o fqdn=sending.example.org -f sender@example.org -t recipient@example.com -u message-subjetc -s smtp3.example.org -m message-text
sendEmail -o fqdn=sending.example.org -f sender@example.org -t recipient@example.com -u message-subjetc -s smtp3.example.org -m message-text -v -v -v -v
If you get an error containing 450 4.7.1
… Helo command rejected: Host not found
, then reject_unknown_helo_hostname
works, but your -o fqdn=
parameter contains an invalid hostname.
More sending examples are in the sendEmail documentation.
If you want to know more about fighting SPAM, then continue at [WayBack] Fighting Spam – What can I do as an: Email Administrator, Domain Owner, or User? – Server Fault
–jeroen
Leave a Reply