Sendmail: rewriting the envelope sender

sendmail

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

Best Answer

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