How to force Sendmail to Rewrite Sender Address?

Need to change sender email id from applmgr@<hostname>.<domain-name> to applmgr@domain-name.

Understand we can change in the sendmail.cf where $j is the hostname.domain-name.. can anyone show the exact value to change?

Thank you.

You need a rewrite rule. They and their placement in different ruleset numbers vary by sendmail version. Each rewrite rule runs until it does nothing, recursively, so be careful. They are a bit like sed s, but I forget already, and have to google. SMTP sendmail.cf
Addresses are already reformatted by the time most rewrite rules see them, adding to the fun. "echo 'some_addr'|sendmail -bt" returns some indication of what rules are up to. (mnemonic - Become Tester -bt)

So, find out which sendmail version you have, and google around for sendmail rewrite rule ruleset.

Not linked to the web, but I stole this a few decades back, for an old sendmail version: http://davidgpickett.home.comcast.net/tips/sendmail_tutorial.txt

This looks just right for you: http://www.sendmail.org/~ca/email/english.html\#SM-MASQUERADE

Hi,
Thanks for your reply. It's really a lot need to absorb :).. will try to pick up. It will be good if someone has already done can show me the steps..:stuck_out_tongue:

Anyway, thanks for sharing.

The last link is just your case, if you have the same version of sendmail.

Sendmail has a history of punishing the rash and reading impaired, and has a very thick, maybe 2 volume, Riley book for the so inclined. I just tinker and google, very carefully. For some rewrites, you cannot get here from there in one line, you have to make something else in the middle of two or more rules to avoid pitfalls like infinite looping.

The version we have is: Sendmail 8.13.8+Sun/8.13.8/Submit

I'm following the steps from Hints about sendmail/e-mail and it seems not work in my environment yet. Not sure the 'smart_host' is the variable or the parameter that we have to follow..
Need to thorough test & trace.. can anyone help me in this?

Removing a top domain is the same as removing a host. Test it like this, for ruleset 10 and below:

$ sendmail -bt -C config_file
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
> 10 someguy@shomehos.somedomain.com
rewrite: ruleset  10   input: someguy @ shomehos . somedomain . com
rewrite: ruleset  50   input: someguy @ shomehos . somedomain . com
rewrite: ruleset  50 returns: someguy @ shomehos . somedomain . com
rewrite: ruleset  94   input: someguy @ shomehos . somedomain . com
rewrite: ruleset  93   input: someguy @ shomehos . somedomain . com
rewrite: ruleset  93 returns: someguy @ shomehos . somedomain . com
rewrite: ruleset  94 returns: someguy @ shomehos . somedomain . com
rewrite: ruleset  10 returns: someguy @ shomehos . somedomain . com
> 

There are so many ruleset and I really don't know which one to change. :confused:

root@devdb # sendmail -bt -d0.1 < /dev/null
Version 8.13.8+Sun
 Compiled with: DNSMAP LDAPMAP LOG MAP_REGEX MATCHGECOS MILTER MIME7TO8
                MIME8TO7 NAMED_BIND NDBM NETINET NETINET6 NETUNIX NEWDB NIS
                NISPLUS PIPELINING SCANF USERDB USE_LDAP_INIT XDEBUG

============ SYSTEM IDENTITY (after readcf) ============
      (short domain name) $w = DEVDB
  (canonical domain name) $j = DEVDB.<domain name>
         (subdomain name) $m = <domain name>
              (node name) $k = DEVDB
========================================================

ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>

[Chapter 29] Rule Sets

Following are the steps I took and it works after the changed.
Masquerade mail as domain.com instead of hostname.domain.com.

  1. cd /usr/lib/mail/cf

  2. cp main.mc sendmail.mc

  3. vi sendmail.mc

Add the following items:

MASQUERADE_AS(`domain.com')dnl
MASQUERADE_DOMAIN(`domain.com')dnl
MASQUERADE_DOMAIN(localhost)dnl
MASQUERADE_DOMAIN(localhost.localdomain)dnl
EXPOSED_USER(`root')dnl
FEATURE(`masquerade_entire_domain')dnl
FEATURE(`masquerade_envelope')dnl

  1. /usr/ccs/bin/make sendmail.cf

  2. cp sendmail.cf /etc/mail/sendmail.cf

  3. /etc/init.d/sendmail restart

Note:
Modify /etc/mail/sendmail.cf

# "Smart" relay host (may be null)
DSmailhost$?m.$m$.