Can postfix forward all outbound email to a relayhost except for local user-to-user email?
5,172
Postfix will only relay non-local mails
to the host specified in the relayhost
. To consider a domain local; the domain has to be listed under mydestination
parameter. So listing example.com
under mydestination
should help you to fix this issue.
#/etc/postfix/main.cf
#...
mydestination = $myhostname, localhost.localdomain, localhost, example.com
#...
Ref: Postfix docs
relayhost (default: empty)
The next-hop destination of non-local mail; overrides non-local domains in
recipient addresses. This information is overruled with relay_transport,
sender_dependent_default_transport_maps, default_transport,
sender_dependent_relayhost_maps and with the transport(5) table.
Related videos on Youtube
Comments
-
DanB almost 2 years
On my home Ubuntu box, postfix is configured to relay all outgoing email to
outgoing.verizon.net
. Unfortunately this includes local user-to-user email (e.g., from local cron jobs to me, or from me to myself) which should not need to travel off-machine. Is there a way to tweak my configuration (below) so local email is delivered without leaving my machine?Note: I don't run a mail server (on port 25) but rather run fetchmail every five minutes to download from an IMAP server.
main.cf:
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = mycomputer.example.com masquerade_domains = example.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = $myhostname, localhost.localdomain, localhost relayhost = [outgoing.verizon.net]:587 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all smtp_sasl_auth_enable = yes smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = smtpd_sasl_auth_enable = no
-
DanB about 10 yearsHmm... With my posted configuration, username@localhost gets forwarded to the relayhost. If your analysis is correct, shouldn't username@localhost be handled entirely locally because "localhost" is listed in mydestination?
-
clement about 10 yearsCan u post the maillog generated by postfix for such a mail?
-
DanB about 10 yearsAh, I was incorrect. username@localhost indeed gets delivered locally. However, mail to just "username" (e.g., "echo foo | /usr/bin/mail username") gets delivered as if I had emailed [email protected].
-
clement about 10 yearsThen I guess ur
myorigin
hasblazemonger.com
. Addblazemonger.com
to mydestination to treat it local.