1

On a postfix mailserver, which is configured to generally send mail directly (internet-site), I want to implement a conditional header check for some receipient domains (in this example to keep it simple just with gmail.com), to let postfix use a smarthost. But, instead of authenticating with the smarthost smtp.google.com, it just keeps sending the mails addressed To: *@gmail* directly (if I set a wrong password on purpose, it does not complain about).

I created the following files in /etc/postfix/:

relay_passwd:

smtp.google.com mygmailaccount@gmail.com:mypassword

header_checks:

^To: <*@gmail*>/ FILTER relay:smtp.gmail.com:25

and referenced them in main.cf with additional options:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/relay_passwd
header_checks = regexp:/etc/postfix/header_checks

now I postmapped the files (and since, restarted postfix too multiple times):

# postmap relay_passwd
# postmap header_checks

and it throws a warning:

postmap: warning: header_checks, line 1: record is in "key: value" format; is this an alias file?

But I guess that's not the problem, is it? Anyway, I must be doing something wrong.

I found the following threads but they're not quite what I want:

Use different relay in postfix

Conditionnal relay in postfix

Different postfix relayhost based on system user?

Is the order in main.cf relevant? Is the regexp in header_checks ok?

sgohl
  • 1,373
  • 1
  • 11
  • 16
  • Looking at http://www.postfix.org/header_checks.5.html the format of the `header_checks` file should be `/pattern/flag action`. Your line is missing the starting `/`. Also, the regular expression is incorrect - `*` means "0 or more occurrences of the preceding character/block". The line should most probably be `/^To: .*<.*@gmail.*>/ FILTER relay:smtp.gmail.com:25` - note the `.*` before the e-mail address to match names. There are still more problems with the regex (like that it will match address foo@gmailwhatever.tld) but this should be a decent start. – piit79 Oct 20 '15 at 11:21

1 Answers1

2

This should do it, your relay configuration looks fine.

/^To: (.*?)@gmail.com$/ FILTER smtp:smtp.gmail.com

Also, you don't need to postmap regexp files.

Source: Marcelog

Jacob Evans
  • 7,636
  • 3
  • 25
  • 55