Discussion:
rewrite sender based on recipient
a***@ukgrid.net
2014-03-04 16:57:48 UTC
Permalink
Hi list,

I'd like to be able to rewrite the sender address for outbound mail
based upon the address to which the mail is being sent. If we can
imagine that the recipient will always be a single email address. Is
this possible?
I've tried the following:

* ${lookup{$recipients}lsearch{/usr/local/scripts/eximrw.conf}\
{$value}fail} Ffrs

But it says "unknown variable name "recipients""

The reason being is that I need to filter mail from an application
which always sends from the same user so that it appears to be from
different users depending upon the "to" address.

Any suggestions?

thanks in advance, Andy.
--
## 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/
Matthew Newton
2014-03-05 11:58:37 UTC
Permalink
Post by a***@ukgrid.net
I'd like to be able to rewrite the sender address for outbound
mail based upon the address to which the mail is being sent. If we
can imagine that the recipient will always be a single email
address. Is this possible?
You need to be very careful doing it of course, but yes.
Post by a***@ukgrid.net
* ${lookup{$recipients}lsearch{/usr/local/scripts/eximrw.conf}\
{$value}fail} Ffrs
But it says "unknown variable name "recipients""
The reason being is that I need to filter mail from an application
which always sends from the same user so that it appears to be from
different users depending upon the "to" address.
Any suggestions?
I would check all the conditions are correct in the ACLs (one
recipient, recipient is the correct one, comes from the correct
host, etc) and set an ACL variable, possibly based on a lookup.

Then use the ACL variable in an expansion in your rewrites.

Matthew
--
Matthew Newton, Ph.D. <***@le.ac.uk>

Systems Specialist, Infrastructure Services,
I.T. Services, University of Leicester, Leicester LE1 7RH, United Kingdom

For IT help contact helpdesk extn. 2253, <***@le.ac.uk>
--
## 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/
a***@ukgrid.net
2014-03-05 13:37:52 UTC
Permalink
Post by Matthew Newton
I would check all the conditions are correct in the ACLs (one
recipient, recipient is the correct one, comes from the correct
host, etc) and set an ACL variable, possibly based on a lookup.
Then use the ACL variable in an expansion in your rewrites.
Thanks for the idea Matthew. I've put the following code in to attempt this:
ACL

acl_check_recipient:
accept hosts = *
set acl_m_a =
${lookup{$recipients}lsearch{/usr/local/scripts/eximrw.conf}\
{$value}fail}

And I've updated my rewrite:

* "${if def:acl_m_a{$acl_m_a} fail}"

But it's not doing any rewrite. I suspect the main issue is that the
ACL isn't matching $recipients to the data in my eximrw.conf file.
Anyway I can't seem to find any info on what the contents of
$recipients looks like so I can't be sure I am searching for the right
string. Can I make exim echo a varibale to the log so I can see what's
in it?

thanks, Andy.
--
## 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/
Dennis Davis
2014-03-05 14:01:59 UTC
Permalink
Date: Wed, 5 Mar 2014 13:37:52
Subject: Re: [exim] rewrite sender based on recipient
...
Anyway I can't seem to find any info on what the contents of
$recipients looks like so I can't be sure I am searching for the
right string. Can I make exim echo a varibale to the log so I can
see what's in it?
See "log_message" and "logwrite". Chapter 42, Section 20 "ACL
modifiers", of the fine manual.
--
Dennis Davis <***@fastmail.fm>
--
## 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/
Jeremy Harris
2014-03-05 14:10:37 UTC
Permalink
Post by a***@ukgrid.net
Post by Matthew Newton
I would check all the conditions are correct in the ACLs (one
recipient, recipient is the correct one, comes from the correct
host, etc) and set an ACL variable, possibly based on a lookup.
Then use the ACL variable in an expansion in your rewrites.
ACL
accept hosts = *
set acl_m_a =
${lookup{$recipients}lsearch{/usr/local/scripts/eximrw.conf}\
{$value}fail}
When was that acl called? If RCPT TO time, $recipients is not
usable. See

http://exim.org/exim-html-current/doc/html/spec_html/ch-string_expansions.html#SECTexpvar
Post by a***@ukgrid.net
Anyway I can't seem to find any info on what the contents of $recipients
looks like so I can't be sure I am searching for the right string. Can I
make exim echo a varibale to the log so I can see what's in it?
warn logwrite = expandable-string

See

http://exim.org/exim-html-current/doc/html/spec_html/ch-access_control_lists.html


PS: messsages can have multiple recipients... Guess what that implies
for that variable and your lookup?
--
Cheers,
Jeremy
--
## 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/
Matthew Newton
2014-03-05 14:48:02 UTC
Permalink
Post by a***@ukgrid.net
Post by Matthew Newton
I would check all the conditions are correct in the ACLs (one
recipient, recipient is the correct one, comes from the correct
host, etc) and set an ACL variable, possibly based on a lookup.
Then use the ACL variable in an expansion in your rewrites.
ACL
accept hosts = *
set acl_m_a =
${lookup{$recipients}lsearch{/usr/local/scripts/eximrw.conf}\
{$value}fail}
Try $local_part@$domain instead of $recipients. The ACL only
checks one recipient at a time (which is why you probably also
need to check that $recipients_count is 1, or similar).

See http://exim.org/exim-html-current/doc/html/spec_html/ch-string_expansions.html#SECTexpvar
for the list of available variables - not all are available at the
same time.

Cheers,

Matthew
--
Matthew Newton, Ph.D. <***@le.ac.uk>

Systems Specialist, Infrastructure Services,
I.T. Services, University of Leicester, Leicester LE1 7RH, United Kingdom

For IT help contact helpdesk extn. 2253, <***@le.ac.uk>
--
## 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/
a***@ukgrid.net
2014-03-05 15:30:47 UTC
Permalink
Post by Matthew Newton
checks one recipient at a time (which is why you probably also
need to check that $recipients_count is 1, or similar).
See
http://exim.org/exim-html-current/doc/html/spec_html/ch-string_expansions.html#SECTexpvar
for the list of available variables - not all are available at the
same time.
Thanks Matthew, I've had a look at this doc and it seems acl_a
variables are suited to the task as opposed to acl_m, so I've changed
that.
I've also tried putting $local_part@$domain as the search string but
its still not matching. BTW For the sake of the testing I am manually
sending a mail to a single recipient so this is controlled.
Is there anything I can do to get it to verbosely show the ACL
processing or see what is in the variable $recipients at a given time?

thanks, Andy.
--
## 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/
Matthew Newton
2014-03-05 15:35:52 UTC
Permalink
Post by a***@ukgrid.net
Post by Matthew Newton
checks one recipient at a time (which is why you probably also
need to check that $recipients_count is 1, or similar).
See http://exim.org/exim-html-current/doc/html/spec_html/ch-string_expansions.html#SECTexpvar
for the list of available variables - not all are available at the
same time.
Thanks Matthew, I've had a look at this doc and it seems acl_a
variables are suited to the task as opposed to acl_m, so I've
changed that.
Unless something has changed recently in exim that I'm not aware
of, $acl_m is the right thing here.
Post by a***@ukgrid.net
its still not matching. BTW For the sake of the testing I am
manually sending a mail to a single recipient so this is controlled.
Is there anything I can do to get it to verbosely show the ACL
processing or see what is in the variable $recipients at a given time?
exim -d -bt ***@example.com

would usually be the right place to start here. Try playing with
the debug options (see exim documentation) and also the -be option
(test expansions).

Matthew
--
Matthew Newton, Ph.D. <***@le.ac.uk>

Systems Specialist, Infrastructure Services,
I.T. Services, University of Leicester, Leicester LE1 7RH, United Kingdom

For IT help contact helpdesk extn. 2253, <***@le.ac.uk>
--
## 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/
a***@ukgrid.net
2014-03-05 16:06:00 UTC
Permalink
Post by Matthew Newton
Unless something has changed recently in exim that I'm not aware
of, $acl_m is the right thing here.
Hi Matthew, I've not attempted this type of config before so I may
well be wrong, but from reading the documenation the only custom
variables I can set in an ACL are $acl_m and $acl_c variables.
Post by Matthew Newton
would usually be the right place to start here. Try playing with
the debug options (see exim documentation) and also the -be option
(test expansions).
I not seeing anything that really helps me with the -bt and -be
options, mainly due to the fact that I'm doing something odd in trying
to change the sender depending on the recipient I think. That is I am
giving the recipient as an arguement to Exim but what really interests
me is the rewriting of the sender (which is root on localhost, which
is fine I can test with this),

thanks, Andy.
--
## 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/
Matthew Newton
2014-03-05 16:19:05 UTC
Permalink
Hi,
Post by a***@ukgrid.net
Post by Matthew Newton
Unless something has changed recently in exim that I'm not aware
of, $acl_m is the right thing here.
well be wrong, but from reading the documenation the only custom
variables I can set in an ACL are $acl_m and $acl_c variables.
Yes - you wrote acl_a, which doesn't exist (afaik - hence my
comment above :) ).

acl_c is for the connection, acl_m is for the message. Therefore
acl_m seems more appropriate if you're altering the sender of an
individual message, rather than all messages in a connection.
Post by a***@ukgrid.net
I not seeing anything that really helps me with the -bt and -be
options, mainly due to the fact that I'm doing something odd in
Look at the -d debugging options. -d+rewrite would be a good
start. If you really want to wade through likely irrelevant stuff,
try -d+all :)

Cheers,

Matthew
--
Matthew Newton, Ph.D. <***@le.ac.uk>

Systems Specialist, Infrastructure Services,
I.T. Services, University of Leicester, Leicester LE1 7RH, United Kingdom

For IT help contact helpdesk extn. 2253, <***@le.ac.uk>
--
## 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/
a***@ukgrid.net
2014-03-05 16:50:48 UTC
Permalink
Post by Matthew Newton
Hi,
Post by a***@ukgrid.net
Post by Matthew Newton
Unless something has changed recently in exim that I'm not aware
of, $acl_m is the right thing here.
well be wrong, but from reading the documenation the only custom
variables I can set in an ACL are $acl_m and $acl_c variables.
Yes - you wrote acl_a, which doesn't exist (afaik - hence my
comment above :) ).
Oops sorry!
Post by Matthew Newton
Look at the -d debugging options. -d+rewrite would be a good
start. If you really want to wade through likely irrelevant stuff,
try -d+all :)
Ok using -d+all -bt I can see a the rewrite being processed:

17:29:19 26335 condition: def:acl_c_a
17:29:19 26335 result: false
17:29:19 26335 expanding: $acl_c_a
17:29:19 26335 result:
17:29:19 26335 skipping: result is not used
17:29:19 26335 failed to expand: ${if def:acl_c_a{$acl_c_a} fail}
17:29:19 26335 error message: "if" failed and "fail" requested
17:29:19 26335 failure was forced


But I really need to see whats happening where $acl_c_a is meant to be
set, in the ACL section as the only thing I can see here is that it is
null.

If I could run the Exim daemon in the foreground with this level of
debugging that might well help. I'm trying this via:

exim -bdf -d+all

But it prints a load of info at startup, gets to "Listening..." and
then I get no more debug output (although it logs normally to the
mainlog).

thanks again, Andy.
--
## 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/
Jeremy Harris
2014-03-05 16:57:06 UTC
Permalink
Post by a***@ukgrid.net
exim -bdf -d+all
But it prints a load of info at startup, gets to "Listening..." and then
I get no more debug output (although it logs normally to the mainlog).
you need to network-connect to it and speak smtp...
--
Cheers,
Jeremy
--
## 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/
a***@ukgrid.net
2014-03-05 18:21:15 UTC
Permalink
Quoting ***@ukgrid.net:

Sorry I'm struggling with some basics here, Im using Exim on Debian
with the split out config. I suspect just putting the ACL in one of
the ACL files isn't sufficient, all the other ACLs are defined in
main, ie


.ifndef MAIN_ACL_CHECK_MAIL
MAIN_ACL_CHECK_MAIL = acl_check_mail
.endif
acl_smtp_mail = MAIN_ACL_CHECK_MAIL

But I don't really get this, Im more familiar with the default
monolothic config where I believe you can just add in ACLs and they'll
all get executed. If I put:

MAIN_ACL_CHECK_RECIPIENTS=acl_check_recipient

Does this mean my ACL will be executed?

Currently my ACL looks like:

acl_check_recipient:
accept
hosts = *
log_message = The value of recipients is $recipients
set acl_c_a =
${lookup{$recipients}lsearch{/usr/local/scripts/eximrw.conf}\
{$value}fail}

Im not getting the log message in the mainlog so I assume its not
being processed.

thanks, Andy.
--
## 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/
a***@ukgrid.net
2014-03-05 23:06:56 UTC
Permalink
Post by a***@ukgrid.net
But I don't really get this, Im more familiar with the default
monolothic config where I believe you can just add in ACLs and
Hi,

ok, I've got rid of the debian multiple config files and obtained a
vanilla monolithic config file for testing.
I'm trying to get the value of $recipients logged to mainlog. Just
testing with "warn logwrite" Im not seeing any data written to the
log, not even plain text. I've stuck a test "warn logwrite" into both
the existing acl_smtp_rcpt and the acl_smtp_data ACLs and also added a
acl_not_smtp ACL with the same but not getting anything written to the
log at all :(

I must be missing something very basic, any ideas?

thanks, Andy.
--
## 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/
Matthew Newton
2014-03-05 23:15:00 UTC
Permalink
Post by a***@ukgrid.net
Sorry I'm struggling with some basics here, Im using Exim on Debian
with the split out config.
You're probably on your own with this one... you'll need to find
the right places to put stuff (or run a normal config instead).
Post by a***@ukgrid.net
accept
hosts = *
log_message = The value of recipients is $recipients
set acl_c_a =
${lookup{$recipients}lsearch{/usr/local/scripts/eximrw.conf}\
{$value}fail}
Im not getting the log message in the mainlog so I assume its not
being processed.
I just tested it here, and it works fine. Watch you put the new
ACL stanza before any lines that accept, e.g. everything from
localhost, to make sure you're actually hitting it.

in the rcpt ACL:

warn
set acl_m_rp = ${lookup{$local_part@$domain}lsearch{/tmp/list}{$value}fail}

in rewrite:

* "${if def:acl_m_rp {$acl_m_rp} fail}" Ff

in /tmp/list:

***@example.com: ***@example.net

correctly rewrites the sender address when sent to
"***@example.com".

Matthew
--
Matthew Newton, Ph.D. <***@le.ac.uk>

Systems Specialist, Infrastructure Services,
I.T. Services, University of Leicester, Leicester LE1 7RH, United Kingdom

For IT help contact helpdesk extn. 2253, <***@le.ac.uk>
--
## 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/
a***@ukgrid.net
2014-03-05 23:28:50 UTC
Permalink
Yep I've been trying both, had just been concentrating on getting
logging working, but had total failure so far on that.
Post by Matthew Newton
I just tested it here, and it works fine. Watch you put the new
ACL stanza before any lines that accept, e.g. everything from
localhost, to make sure you're actually hitting it.
Thats great! I've put in a vanilla config file now but it still doesnt
work for me. I've tried adding the code:

warn
set acl_m_a =
${lookup{$local_part@$domain}lsearch{/usr/local/scripts/eximrw.conf}{$value}fail}

to both existing ACLs and added in a new one for non-SMTP data which I
assume will work for local email sent from the command line.
Guess will try sending SMTP via telnet next in case it has something
to do with the sending from the local shell...

thanks, Andy.
--
## 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/
a***@ukgrid.net
2014-03-05 23:39:50 UTC
Permalink
Post by a***@ukgrid.net
Guess will try sending SMTP via telnet next in case it has something
to do with the sending from the local shell...
Ok yeah its working for me too when sending via SMTP! :)

Shouldn't the acl acl_not_smtp allow me to do the same rewrite for
mail sent from the system shell?

thanks a lot! Andy.
--
## 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/
Ian Zimmerman
2014-03-08 23:53:02 UTC
Permalink
On Wed, 5 Mar 2014 23:15:00 +0000
Matthew Newton <***@leicester.ac.uk> wrote:

Andy> Sorry I'm struggling with some basics here, Im using Exim on
Andy> Debian with the split out config.

Matthew> You're probably on your own with this one... you'll need to
Matthew> find the right places to put stuff (or run a normal config
Matthew> instead).

FWIW, under the hood exim uses a single configuration file even on
Debian. It is just well hidden in /var/lib/exim4/config.autogenerated.
You can just edit that file and restart the daemon to test changes.
Once you have it working, edit the snippet under /etc/exim4/conf.d and
run dpkg-reconfigure exim4-config, which will regenerate the single file
and restart exim again.

You know which snippet is responsible for which part of the single file
by strategically placed comments.
--
Please *no* private copies of mailing list or newsgroup messages.

gpg public key: 2048R/984A8AE4
fingerprint: 7953 ADA1 0E8E AB57 FB79 FFD2 360A 88B2 984A 8AE4
Funny pic: http://bit.ly/ZNE2MX
--
## 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/
Dominic Benson
2014-03-09 07:56:15 UTC
Permalink
Post by Ian Zimmerman
On Wed, 5 Mar 2014 23:15:00 +0000
<snip>
Post by Ian Zimmerman
FWIW, under the hood exim uses a single configuration file even on
Debian. It is just well hidden in /var/lib/exim4/config.autogenerated.
You can just edit that file and restart the daemon to test changes.
While this is true, the init script on Debian regenerates the config.autogenerated file on start/restart - so if you take this approach you'll need to kill and launch the daemon by hand.
Post by Ian Zimmerman
Once you have it working, edit the snippet under /etc/exim4/conf.d and
run dpkg-reconfigure exim4-config, which will regenerate the single file
and restart exim again.
Per the above, a restart will suffice.
Debian's exim4-config has an option to use single file or split config. Personally, I like the split config (but I seem to be in a minority in holding that view on this list), but if you use the single file mode then /etc/exim4/exim.conf.template (file name?) is used as a template, with the defines from dpkg merged in.

IIRC you can also create a completely vanilla exim config and put it at /etc/exim4/exim.conf and it will be [copied to autogen and] used.

In my opinion it depends how close to the typical Debian configuration your needs are, and who else is admin-ing. It can be somewhat confusing if the dpkg-reconfigure (to change accepted domains/relay hosts/smarthost) doesn't work. But it is even worse if it *half* works.


Dom
--
## 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/
Loading...