1

I am trying to find a way to rewrite the envelope from address based on what the envelope from currently is. This question here also has what I need:

Sendmail: Setting envelope sender to a fixed value

That issue has the following code:

SEnvFromSMTP
R$+ <@foo.org.>   $: john.doe <@example.net.>
divert(0)

This works to change the Envelope from address to john.doe@example.net if it was a @foo.org address. I need to take this example and add a few more matches. For example I may also want to change @test.com to john.doe@example.net. No manner of stacking the rewrite rules resulted in anything that worked.

I was reading this page:

http://www.sendmail.org/~ca/email/doc8.12/op-sh-5.html

I am pretty sure this will require some regex, but I am having trouble figuring out how it all needs to come together. Also really hoping to keep any added config in the sendmail.mc file.

Thanks

2 Answers2

1

There MUST BE a tab (\t) before $: in the R line.

LOCAL_CONFIG
C{FixSenderDomains}foo.org test.com
MAILER_DEFINITIONS
SEnvFromSMTP
R$+ <@ $={FixSenderDomains} .>   $: john.doe <@example.net.>
divert(0)

You can test it using the script below

#!/bin/sh
/usr/sbin/sendmail -d21.12 -bt <<END
/tryflags es
/try esmtp xyz@test.com
END
AnFi
  • 6,278
  • 1
  • 15
  • 27
  • Ok, so I now have the following config in my sendmail.mc file:

    MAILER(smtp)dnl LOCAL_CONFIG C{FixSenderDomains}domain1.com domain2.com MAILER_DEFINITIONS SEnvFromSMTP R$+ <@ $={FixSenderDomains} .> $: john.doe <@example.net.> divert(0)

    It is rewriting the domain for "domain2.com" but not for "domain1.com", and yes I do have a TAB before the "$: john..." int he R line.

    – alaphoid Apr 03 '17 at 14:35
  • see the attached test script/procedure – AnFi Apr 03 '17 at 15:25
1

I can't seem to format a comment without it looking really messy, so creating an answer.

Testing with the prescribed method, this is what I am seeing:

Using the following config:

LOCAL_CONFIG
C{FixSenderDomains}test1.com test2.com
MAILER_DEFINITIONS
SEnvFromSMTP
R$+ <@ $={FixSenderDomains} .>      $: john.doe <@example.net.>
divert(0)

I get the following output when testing mail from test1.com and test2.com (seperate tests):

rewritten as: test < @ test1 . com . >
-----trying rule: $+ < @ $={FixSenderDomains} . >
-----rule matches: $: john . doe < @ example . net . >

rewritten as: test < @ test2 . com >
-----trying rule: $+ < @ $={FixSenderDomains} . >
----- rule fails

So have been unable to figure out why one domain is being evaluated as < @ test1 . com . > and the other < @ test2 . com > (missing the trailing period). If I change the config to the following it works:

LOCAL_CONFIG
C{FixSenderDomains} test1.com. test2.com.
C{FixSenderDomains} test1.com test2.com
MAILER_DEFINITIONS
SEnvFromSMTP
R$+ <@ $={FixSenderDomains} >      $: john.doe <@example.net.>
divert(0)

I don't need to do this for too many domains so it wouldn't be a big deal if I had to do the config like above, but I would still really like to be able to explain this behavior.