[exim] [Solved] Select transport in router, depending of dom…

Etusivu
Poista viesti
Vastaa
Lähettäjä: Prosto Admin
Päiväys:  
Vastaanottaja: exim-users
Aihe: [exim] [Solved] Select transport in router, depending of domain
On 11/12/2015 02:41 PM, Mike Brudenell wrote:
> Hi,
>
> To expand on the previous reply, the syntax you're using for the "if"
> statements is totally incorrect, as is for matching strings and so on.
>
> To get you started with the syntax of expanding strings look at the
> /String expansions/ chapter of the /Exim Specification/ for the version
> of Exim that you're using. For example this chapter for the current for
> version of Exim can be found at:
>
>     http://exim.org/exim-html-current/doc/html/spec_html/ch-string_expansions.html

>
>
> Here you'll see that the general format of an if…then…else… statement
> doesn't contain keywords like "then", "elif" or "else". Instead it
> actually looks like this:
>
>     ${if <condition> {<string1>}{<string2>}}

>
> where <string1> is the string that's substituted if the <condition> is
> true, and <string2> if it is false. Each of these strings can of course
> contain further "${if…}" expansions should you need.
>
> In a different section of the same chapter you'll find the proper syntax
> for the "match" expansion condition. Its general form is:
>
>     match {<string1>}{<string2>}

>
>
>     (If you're just wanting to test for simple equality use "eq" or
>     "eqi" instead of "match".)

>
>
> You would place this in as the <condition> in the ${if…} expression,
> possibly combining several with "and" or "or" operators as needed.
> These, too, are explained in a different section of the same chapter.
>
> Cheers,
> Mike Brudenell
>
> On 11 November 2015 at 13:53, Prosto Admin <prostoadmin@???
> <mailto:prostoadmin@litkk.com.ua>> wrote:
>
>     Hi all!

>
>     I have two local domains (2 active directory domains (cross
>     truested)) in one local network.
>     And i have two external domain (valid MX).
>     for example:
>     local: domain1.local and domain2.local
>     external: domain1.external and domain2.external

>
>     Need configuration - local domains can cross writing mails to each
>     one, and if local user write to external world, it sender address
>     rewrite to external domain: "domain1.local" to "domain1.external".
>     If from external world some one write to my external domain, exim
>     need rewrite recipient address to local domain.

>
>     Exim auth user by LDAP, and all work.
>     For implement address rewrite, i declare for each domain separate
>     transport.

>
>     I need on router "dnslookup" select transport by it $domain section.

>
>
>     My example of router dnslookup (it not work):
>     -----------------------------------------------------------
>     dnslookup:
>        driver = dnslokup
>        domains = ! +internal_domains : ! +external_domains
>        transport = ${
>          if {$domain} match {\N\.domain1\.local$\N}
>            then
>              domain1_local_smtp
>          elif
>            {$domain} match {\N\.domain2\.local$\N}
>            then
>              domain2_local_smtp
>          elif
>            {$domain} match {\N\.domain1\.external$\N}
>            then
>              domain1_external_smtp
>          elif
>            {$domain} match {\N\.domain2\.external$\N}
>            then
>              domain2_external_smtp
>          elif
>             fail
>          endif
>        }
>        no_more
>     -----------------------------------------------------------

>
>
>     Transport example:
>     -----------------------------------------------------------
>     domain1_local_smtp:
>        headers_rewrite = *@domain1.external \

>
>     ${lookup{$0}lsearch{/usr/local/etc/exim/rewrite_external_domain1.lst}{$value}fail}
>        return_path = \
>          ${if match{$return_path}{\N^([^@]+)@(.*)\.domain1\.local$\N} \
>          {\

>
>     ${lookup{$0}lsearch{/usr/local/etc/exim/rewrite_external_domain1.lst}{$value}fail}\
>           }\
>     fail}
>     -----------------------------------------------------------

>
>     Router example not work, but please suggest construction for it
>     works as i planned. Or point my to documentation that can by explain
>     how make rewriting for this case.

>
>     --
>     ## List details at https://lists.exim.org/mailman/listinfo/exim-users
>     ## Exim details at http://www.exim.org/
>     ## Please use the Wiki with this list - http://wiki.exim.org/

>
>
>
>
> --
> Systems Administrator & Change Manager
> IT Services, University of York, Heslington, York YO10 5DD, UK
> Tel: +44-(0)1904-323811
>
> Web:www.york.ac.uk/it-services <http://www.york.ac.uk/it-services>
> Disclaimer:www.york.ac.uk/docs/disclaimer/email.htm
> <http://www.york.ac.uk/docs/disclaimer/email.htm>



Problem solved:

While somebody in the world, send mail to user admin@???,
MTA reroute it to admin@??? by "external_to_local" router (it
rewrite recipient in DATA section) and dovecot delivery it to mailbox of
local user.

If some local user write to another local user in local corp. domain,
it not rewriting or rerouting, just used "localuser" router.

If some local user writing mail to external world, used "dnslookup"
router, it use "ext_smtp" transport.
This "ext_smtp" transport rewrite sender and return path to my
external domain by searching in "alias file".



Aliases file example:

---/usr/local/etc/exim/rewrite_external.lst---
admin@??? admin@???
administrator@??? administrator@???
---

---/usr/local/etc/exim/rewrite_local.lst---
admin@??? admin@???
administrator@??? administrator@???
--


------------ Config example -------------------------------------

begin routers

external_to_local:
driver = redirect
domains = +external_domains
allow_fail
allow_defer
data =
${lookup{$local_part@$domain}lsearch{/usr/local/etc/exim/rewrite_local.lst}}
pipe_transport = dovecot_delivery

localuser:
driver = accept
domains = +internal_domains
transport = dovecot_delivery
cannot_route_message = Unknown user

dnslookup:
driver = dnslookup
domains = ! +internal_domains : ! +external_domains
transport = ext_smtp
ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8
no_more

-----------------------------------------------------------


begin transports

ext_smtp:
driver = smtp
headers_rewrite = *@+internal_domains
${lookup{$0}lsearch{/usr/local/etc/exim/rewrite_external.lst}{$value}fail}
return_path =
${lookup{$return_path}lsearch{/usr/local/etc/exim/rewrite_external.lst}{$value}fail}


dovecot_delivery:
driver = pipe
command = /usr/local/libexec/dovecot/dovecot-lda -d
$local_part@$domain -f $sender_address
message_prefix =
message_suffix =
delivery_date_add
envelope_to_add
return_path_add
log_output
user = maildir
temp_errors = 64 : 69 : 70: 71 : 72 : 73 : 74 : 75 : 78

remote_smtp:
driver = smtp

-----------------------------------------------------------