The Exim FAQ

Contents   Previous   Next


Q0801:  How can I get Exim to strip the hostname from the sender's address?

A0801:  If you set up a rewriting rule in the following form:

   *@*.your.domain  $1@your.domain

then Exim will rewrite all addresses in the envelope and the headers, removing anything between @ and your.domain. This applies to all messages that Exim processes. If you want to rewrite sender addresses only, the the rule should be

   *@*.your.domain  $1@your.domain  Ffrs

This applies the rule only to the envelope sender address and to the From:, Reply-to:, and Sender: headers.

Q0802:  I have Exim configured to remove the hostname portion of the domain on outgoing mail, and yet the hostname is present when the mail gets delivered.

A0802:  Check the DNS record for your domain. If the MX record points to a CNAME record instead of to an A record, some MTAs (not Exim) are liable to rewrite addresses, changing your domain name to its “canonical” form, as obtained from the CNAME record.

Q0803:  I want to rewrite local addresses in mail that goes to the outside world, but not for messages that remain within the local intranet.

A0803:  You can use the headers_rewrite option on a transport to do this. The rewriting will then apply to just those copies of a message that pass through the transport. The return_path option can similarly be used to rewrite the sender address. There is no way of rewriting recipient addresses at transport time. However, as these are by definition remote addresses, you probably don't want to rewrite them.

You have to set up the configuration so that it uses different SMTP transports for internal and external mail. If you are using a single router in both cases, you could configure it like this:

     driver = dnslookup
     transport = ${if match{$domain}{\N\.my\.domain$\N}{int_smtp}{ext_smtp}}

This example uses the int_smtp transport for domains ending in .my.domain, and ext_smtp for everything else. The ext_smtp transport could be something like this:

     driver = smtp
     headers_rewrite = *@*.my.domain \
     return_path = \
       ${if match{$return_path}{\N^([^@]+)@(.*)\.my\.domain$\N}\

This example uses a separate file of local-to-external address translations for each domain. This is not the only possibility, of course. The headers_rewrite and return_path options apply the same rewriting to the header lines and the envelope sender address, respectively.

Q0804:  I'm using this rewriting rule to change login names into “friendly” names, but if mail comes in for an upper case login name, it doesn't get rewritten.

 	 *@my.domain	 ${lookup{$1}dbm{/usr/lib/exim/longforms}\
			 {$value}fail}@my.domain bcfrtFT

The longforms database has entries of the form:

   ano23: A.N.Other

A0804:  Replace $1 in your rule by ${lc:$1} to force the local part to lower case before it is used as a lookup key.

Q0805:  Is it possible to completely fail a message if the rewrite rules fail?

A0805:  It depends on what you mean by “fail a message” and what addresses you are rewriting. If you are rewriting recipient addresses for your local domain, you can do:

 	 *@dom.ain  ${lookup{$1}dbm{/wher/ever}{$value}{failaddr}}  Ehq

and in your alias file put something like

 	 failaddr:   :fail: Rewriting failed

This fails a single recipient - others are processed independently.

Q0806:  I'm using $domain as the key for a lookup in a rewriting rule, but its contents are not being lowercased. Aren't domains supposed to be handled caselessly?

A0806:  The value of $domain is the actual domain that appears in the address. It could of course be lower cased, but I know that would cause some unhappiness, because some people have mixed-case domain names which look silly if the case is changed. Thus, one wants to preserve the case in rewrites such as

   *@*   something@$domain

because “therap” doesn't look like two words. I know it seems trivial, but it is important to some people - especially if by some unfortunate accident the lowercased word is something indecent.

You can trivally force lower casing by means of the ${lc: operator. Instead of $domain write ${lc:$domain}.

Q0807:  I want to rewrite local sender addresses depending on the domain of the recipient.

A0807:  In general, this is not possible, because a message may have more than one recipient and Exim keeps just a single copy of each message. It may also deliver one copy of a message with several recipient addresses. You can do an incomplete job by using a regular expression match in a rewrite rule to test, for example, the contents of the To: header. This would work except in cases of multiple recipients.

Contents   Previous   Next