9

I wish to set up Postfix to use an external relay depending on the destination hostname, ie:

  • If destination hostname is *.outlook.com, use relay some_smtp.example.com
  • If any other destination hostname, use local relay

What I mean by destination hostname is the hostname obtained from MX record. If the recipient domain has MX record microsoft-com.mail.protection.outlook.com, then use a different relay

I know it is possible to specify a relay depending on the sender address (using sender_dependent_relayhost_maps), but it's impractical in my situation.

The goal is to use a different relay for finicky destination hosts: maybe Mandrill, or another Postfix installation.

6

You can setup a transport map to selectively choose mails with @outlook.com as destination address and relay them via some_smtp.example.com as shown below.

Add the entry below to /etc/postfix/transport

outlook.com smtp:[some_smtp.example.com]

Add the entry below to /etc/postfix/main.cf

transport_maps = hash:/etc/postfix/transport

Restart postfix after the following command

sudo postmap /etc/postfix/transport
1
  • Thanks for your answer. Please see my edit about "destination hostname". Should have been more specific. – BinaryDeuce Jan 29 '15 at 16:48
6

Arul's answer was perfect for transport based on recipient domain. However, bencaue you refer to MX record hostname instead recipient domain, the answer was non-applicable.

One solution is using check_recipient_mx_access. Snippet from official docs

check_recipient_mx_access type:table

Search the specified access(5) database for the MX hosts for the RCPT TO domain, and execute the corresponding action. Note: a result of "OK" is not allowed for safety reasons. Instead, use DUNNO in order to exclude specific hosts from blacklists. This feature is available in Postfix 2.1 and later.

For your case, just put check_recipient_mx_access hash:/etc/postfix/finickydestination in appropriate place smtpd_*_restriction. In that file put the hostname

# /etc/postfix/finickydestination
.outlook.com FILTER smtp:[some_smtp.example.com]

Don't forget to postmap the file and execute postfix reload.

Reference(s):

1
  • 1
    This of course is not working (unfortunately). Put in the smtpd_recipient_restriction, results in: postfix/smtpd: warning: do not specify lookup tables inside SMTPD access maps postfix/smtpd: warning: define a restriction class and specify its name instead. – user221326 Mar 31 '15 at 14:50
2

As @user221326 (i don't have enough rep to comment myself) pointed out @masegaloeh answer will NOT work as check_recipient_mx_access expects a access table with a ACTION

More info in the man page

The action you want is FILTER so something like

.outlook.com FILTER smtp:[some_smtp.example.com]

Note if you have multiple FILTER only the last will fire so ensure this comes after everything else.

Furthermore .outlook.com will only catch sub/super domains (e.g. whatever.protection.outlook.com) if smtpd_access_maps is NOT in parent_domain_matches_subdomains, otherwise you want outlook.com (no leading dot)

Lastly keep in mind that this action applies to the whole message as soon as one recipients MX matches the domain, which should be a non-issue as long as your defined target isn't a MDA.

Cheers

1
  • This change is now propagated to the original @masegaloeh answer. – Marki555 2 days ago
0

2021 Update

I did try all this, but it did not seems to work. The solution I present was "assembled" from several sources.


in main.cf you need to add following:

smtpd_sender_restrictions   =
        check_recipient_mx_access   pcre:/etc/postfix/mxtransport

then you do /etc/postfix/mxtransport as "usual":

/google\.com$/              FILTER smtp:[smtp.com]:25
/googlemail\.com$/          FILTER smtp:[smtp.com]:25
/protection\.outlook\.com$/ FILTER smtp:[smtp.com]:25

/spamexperts\.com$/         FILTER smtp:[smtp.com]:25
/spamexperts\.net$/         FILTER smtp:[smtp.com]:25
/spamexperts\.eu$/          FILTER smtp:[smtp.com]:25

This assures, that emails sent to google / outlook / spamexperts clients (for example something@google.com, something@hotmail.com, something@tui.de etc), will go via third party route (smtp.com) instead via local IP.


I am still using Postfix 2.10.1 (CentOS 7)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.